我试图从旧的,裸的git存储库的备份中恢复一些文件,这些存储库最初是在Windows中使用Tortoise Git进行管理的(如果这有任何区别)但是当我在Mac上克隆它时我得到了消息:
警告:您似乎克隆了一个空存储库。
我理解此警告,但我不相信此存储库 为空。我一直试图更多地了解git的工作方式,但我似乎无处可去,这是我需要你帮助的地方。
查看"远程"中的文件(它实际上是坐在外部硬盘上)存储库中有以下文件/文件夹;是什么让我认为存储库实际上不是空的是因为objects
文件夹包含161个子文件夹,大约87MB的数据:
master
文件的内容是校验和(我猜测)(我认为)指向master
分支的头部。但是,运行命令git branch -a
不会返回任何内容。
我也尝试使用gitk --all
,但这会出错:
解析修订时出错:未知修订版HEAD
我查看了修复git存储库并引导我尝试创建一个新的repo,复制.pack
文件并使用git unpack-objects < my.pack
解压缩它们。这在objects
文件夹中创建了大量文件夹/文件,但git branch
和git checkout
等命令仍然失败。
有人可以建议一种方法来获取objects
文件夹中的文件吗?
更多信息
这是克隆项目然后尝试使用它时的命令行输出:
$ mkdir project
$ git init project
Initialized empty Git repository in /Users/tony/git/project/.git/
$ cd project/
$ git clone /Volumes/Backup/git/db/reporting
Cloning into 'reporting'...
warning: You appear to have cloned an empty repository.
done.
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
$ git branch -a
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
branch
命令的结果为空,结帐导致错误。我认识到初始提交&#39;这是我第一次将文件添加到新仓库时通常使用的信息。
我尝试将文件解压缩到一个新的仓库中,这是该流程的命令行输出:
$ mkdir unpack
$ git init unpack/
Initialized empty Git repository in /Users/tony/git/unpack/.git/
$ cd unpack/
$ git unpack-objects < /Volumes/Backup/git/db/reporting/objects/pack/pack-9e157880d61b9a9cecba012130de16cc71f898b5.pack
Unpacking objects: 100% (185/185), done.
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
$ git branch
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
我接下来尝试的是将一个简单的文本文件添加到repo中,这样可以恢复master
分支:
$ pico readme
$ ls
readme
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git commit -m 'added a file'
[master (root-commit) 3ec34b9] added a file
1 file changed, 1 insertion(+)
create mode 100644 readme
$ git status
On branch master
nothing to commit, working directory clean
$ git branch
* master
$ git checkout master
Already on 'master'
添加新文件使我能够再次看到分支,但遗憾的是我仍然无法从对象文件夹中恢复文件。
回应Vorac的评论,这是我不首先创建回购时的输出:
$ git clone /Volumes/Backup/git/db/reporting
Cloning into 'reporting'...
warning: You appear to have cloned an empty repository.
done.
$ ls
reporting
$ cd reporting/
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
$ git log
fatal: your current branch 'master' does not have any commits yet
$ git show
fatal: your current branch 'master' does not have any commits yet
config
文件的内容
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
正如Roman所建议的那样,我在respoitory的副本上运行了fsck
命令,这是输出:
$ git fsck --full
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
notice: No default references
答案 0 :(得分:1)
看起来你有一个双存储库 - 你的裸存储库是一个空的非裸存储库的工作副本。我不知道您的文件管理器是否显示隐藏文件,但您应该在裸存储库文件夹中查找.git
文件夹(例如,使用ls -al
);您也可以通过在裸存储库中运行git status
来确认这一点 - 如果我没错,它将打印如下内容:
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# HEAD
# config
# description
# hooks/
# info/
# refs/
#
nothing added to commit but untracked files present (use "git add" to track)
如果是这种情况,您应该将两个 - 移动.git
文件夹分开(或者只是复制存储库并从副本中删除.git
)。