我正在尝试从一个旧的,裸的git存储库的备份中恢复一些文件,这些存储库最初是在
Windows中使用Tortoise
Git进行管理的(如果这有任何区别)但是当我在Mac上克隆它时,我收到消息:
warning: You appear to have cloned an empty repository.
我理解这个警告,但我不相信这个存储库是空的.我一直在努力学习更多关于git工作原理的方法,但我似乎无处可去,这是我需要你帮助的地方.
查看“远程”(它实际上位于外部HDD)存储库中的文件有以下文件/文件夹;是什么让我认为存储库实际上不是空的是因为objects文件夹包含161个子文件夹,大约87MB的数据:
主文件的内容是校验和(我猜)(我认为)指向主分支的头部.但是,运行命令git branch -a不会返回任何内容.
我也尝试过使用gitk –all但是会出错:
Error parsing revisions: unknown revision HEAD
我查看了修复git存储库,并引导我尝试创建一个新的repo,复制.pack文件并使用git unpack-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命令的结果为空,结帐导致错误.我认识到’初始提交’消息,因为这是我第一次将文件添加到新仓库时通常使用的消息.
我已经尝试将文件解压缩到一个新的repo,这是该进程的命令行输出:
$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添加一个简单的文本文件,这设法恢复主分支:
$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
配置文件的内容
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
正如Roman所建议的,我在resository的副本上运行了fsck命令,这是输出:
$git fsck --full
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
notice: No default references
最佳答案 看起来你有一个双存储库 – 你的裸存储库是一个空的非裸存储库的工作副本.我不知道您的文件管理器是否显示隐藏文件,但您应该在裸存储库文件夹中查找.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).