在强制关闭虚拟机后,我收到了这条 git 消息,这显然损坏了 git 索引
Git: Failed to read object abcdef.... Invalid argument
我查看了这些现有的答案
似乎没有一个工作。
在强制关闭虚拟机后,我收到了这条 git 消息,这显然损坏了 git 索引
Git: Failed to read object abcdef.... Invalid argument
我查看了这些现有的答案
似乎没有一个工作。
让我们进入它并尝试解决它。仅在也不起作用时才使用此方法git reflog
,因为显然您的索引已损坏,并且 reflog 无法从损坏的索引中读取。
打开你的.git/
文件夹
查看名为HEAD
.
这有你的 git 当前所在的分支的名称。
现在查找一个名为ORIG_HEAD
.
这probably
具有 git 能够注册的最后一次良好提交的 SHA。如果是的话,瞧!
复制它(比如 X),在终端执行:
git show X > interim.patch
这会将您上次成功的更改复制到标准差异中。
还要将此 SHA (X) 复制到HEAD
文件的内容中。
这告诉 git 将此更改视为当前位置,它可以接受,因为它已经在一段时间前注册了它。
到现在为止,如果你做一个git branch
,你就会搬到(no branch)
.
所以现在你有了你的改变。这样做git checkout -f <branch-name>
会用远程内容覆盖您的更改,但您仍然在该补丁中拥有它们。
所以现在,你是
做一个git apply interim.patch
如果顺利的话,意味着你有你的改变。
然后继续正常的 git 步骤。
git add .
git commit -am 'Message'
你又恢复了正常的平静生活。
Using @Arindam's answer above didn't work for me, but a variation of it did, I hope someone else finds it useful:
At this point you're in GIT limbo. You can't checkout a new branch with the state of the current branch, likely because the reflog is corrupted.
Before you continue:
In my scenario I knew roughly when the files who's changes I had "lost" were last edited - approx 4 hours ago - so running the following fetches all my project files that were edtited between my last successful commit and now:
$> cd my/project/dir
$> find . -type f -mmin -240 -exec grep -l "$1" {} \; | xargs ls -l
Copy these files somewhere else manually (e.g. into /tmp/backup) or by extending the command to do it manually (I had about a dozen, so by hand wasn't such a chore)
Edit .git/ORIG_HEAD and do the same
$> git branch
GIT should tell you "(no branch)"
$> git log
GIT should give you the log message for the SHA1 you noted above
Now create a new branch:
$> git checkout -b my_new_branch
Now copy all the files from /tmp/backup into their correct locations and run:
$> git commit -a -m "Some commit"
You're done. You should now be in a new branch called "my_new_branch" with all the files modified between the last most successful commit and now committed and safe.
Now tar this lot up and back this up somewhere!
将项目克隆到另一个目录中。在那里调查您是否拥有原始文件中的所有参考。