修复损坏的git repo-如何重新开始 [英] Repair a broken git repo - how to have a fresh start
问题描述
我是git的新手,对我的repo的工作方式感到沮丧..或者在这种情况下无法正常工作..所以我从git hub删除了它,删除了项目上的git文件夹,并打算重新开始.
I am somewhat of a newbie with git and was frustrated with how my repo was working.. or in this case not working.. so I deleted it off of git hub, deleted the git folder on the project and was planning to start fresh.
现在,当我尝试建立一个新的仓库时,我收到很多消息,例如:
Now when i try and set up a fresh repo I am getting a lot of messages like :
warning: You appear to be on a branch yet to be born.
warning. Forcing checkout of HEAD
当我尝试运行第一次提交时,我看到了:
when I try and run the first commit I see :
error: invalid object 8bcb4b5fd612e3ad55fb07e4bed087c55afd0861
fatal: git-write-tree: error building trees
我运行了git fsck,发现我缺少一堆斑点.
I ran git fsck and see that I am missing a bunch of blobs.
我怎么能擦拭干净然后再试一次?
How can I just wipe the slate clean and try again?
推荐答案
好,
- 具有备份
- git clean -dfx.
- mv .git /tmp/ _git.backup
- git init
- git add.
- git commit -m'在救援操作后重新启动仓库'
- have backups
- git clean -dfx .
- mv .git /tmp/_git.backup
- git init
- git add .
- git commit -m 'restart repo after rescue operation'
请注意clean
步骤,该步骤可防止将许多以前未跟踪的内容添加到新存储库中.一个好的.gitignore可以有效防止这种情况的发生.
Note the clean
step that prevents a lot of previously untracked stuff from being added to the new repo. A good .gitignore goes a long way to prevent effects like that.
如果需要,您可以手动迁移部分/全部旧配置,例如
If you want, you can manually migrate some/all of the old configuration, like
vim -d _git.backup/config .git/config
(或简单地复制它)
我不会详细介绍对潜在的远程克隆/分支的影响:)
I'll not go into obvious details about impact on potential remote clones/branches :)
有很多方法可以调和诸如此类的东西,但就目前而言,这似乎可以回答您的问题.
There are ways to reconcile things like that, but for now, this seems to answer your question.
这篇关于修复损坏的git repo-如何重新开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!