无法使用 git status 修复坏对象 HEAD 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7378738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cant fix bad object HEAD error with git status
提问by Rob
My Battery died on my macbook when pushing my repo.
Now I cannot run git status
推送我的回购时,我的电池在我的 macbook 上没电了。现在我不能跑git status
$ git status
fatal: bad object HEAD
fatal: git status --porcelain failed
I've tried a few suggestions ive found for fixing bad object errors.
我已经尝试了一些我发现的修复坏对象错误的建议。
$ git fsck --full
dangling tree 65e856976b7aa7c73f15cd71defedb8a3d622a10
I've tried git prune
and git prune-packed
我试着git prune
和git prune-packed
I can still commit, stash, push, it appears to be just affecting git status
我仍然可以提交、存储、推送,它似乎只是影响 git 状态
Andy ideas?
安迪的想法?
Thanks
谢谢
回答by dasrecht
I guess you solved this problem already but i had this to and could fix it simply by run
我猜你已经解决了这个问题,但我已经解决了这个问题并且可以通过运行来解决它
git pull
This has resulted into a working condition. eventough your files are intact you should backup your local git directory and then run the git pull. after that you should be back in business.
这导致了工作状态。即使您的文件完好无损,您也应该备份您的本地 git 目录,然后运行 git pull。之后你应该重新开始营业。
If there are files deleted (it should not happen) you can copy them back over a working checkout and commit them from there.
如果删除了文件(不应该发生),您可以将它们复制回有效的检出并从那里提交。
回答by wRAR
If your .git/HEAD
is corrupted or points to a corrupted object, you can change it manually or by git checkout
.
如果您.git/HEAD
已损坏或指向损坏的对象,您可以手动或通过git checkout
.
回答by philburk
This happened to me when I accidentally added my bin/ folder in an Eclipse Java project.
当我不小心在 Eclipse Java 项目中添加了 bin/ 文件夹时,这发生在我身上。
Using 'git pull' did not work for me.
使用“git pull”对我不起作用。
I fixed it by:
我通过以下方式修复它:
- closing Eclipse
- rm -rf bin
- git rm bin
- 关闭 Eclipse
- rm -rf bin
- git rm bin
Then I was able to 'git commit' and continue normally.
然后我能够'git commit'并正常继续。
回答by Leye Odumuyiwa
This worked for me:
这对我有用:
git fetch origin
git reset --hard origin/master
回答by MakerMax
git checkout -f *branchname*
worked for me.
git checkout -f *branchname*
对我来说有效。
回答by joshy
Try add all of your modified files with git add filepath/file.ext
before the git status.
尝试git add filepath/file.ext
在 git status 之前添加所有修改过的文件。