重置后Git commit失败--hard。没有找到fsck,没有在reflog [英] Git commit lost after reset --hard. Not found by fsck, not in reflog

查看:128
本文介绍了重置后Git commit失败--hard。没有找到fsck,没有在reflog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想清除一些未提交文件的工作目录,但意外地运行了 git reset --hard



<我意识到我已经失去了以前的(未推送)提交,所以我运行了 git reset --hard ORIG_HEAD 。这并没有让我失去我的提交。



我运行了 git reflog ,但提交没有在那里列出。我也运行了 git fsck --lost-found ,但是列表中没有提交,只有几个不相关的blob和树。



由于我找不到任何丢失提交的引用(除了 .git / COMMIT_EDITMSG ,它仍然有相关的提交消息和更改列表),我不知道如何去恢复提交。



有什么方法可以让丢失的提交回来,或者我应该准备好全部提交吗?不知道为什么你无法找到你的提交,就像@ twalberg关于 git的注释一样> 重设--hard 是正确的。不过,您可以尝试一些事情。



您有要查找的提交的消息( .git / COMMIT_EDITMSG )。如果编写 COMMIT_EDITMSG ,那么该特定的提交应该是某处。从消息中挑出一些相当独特的文本,并尝试这样做:



git log -g --grep =<你的提交信息>



它将通过reflog并找到匹配丢失提交信息中文本的提交。 b
$ b

如果没有这个运气,你可以尝试查看每个分支上的所有提交:

git log --all --grep =<从你的提交信息中特定的东西>



一旦找到提交哈希,它出来,建立一个新的分支,将它合并回你当前的分支,等等。然而,如果这一切都失败了,你可以尝试查看存储库中的对象,但不是任何提交的一部分(例如,添加到索引中,但没有提交)。这个答案可以帮助你:

https://stackoverflow.com/a/7376959/845716


I wanted to clear my working directory of some uncommitted files, but accidentally ran git reset --hard.

I realized that I had lost the previous (un-pushed) commit, so I ran git reset --hard ORIG_HEAD. This did not get me to my lost commit.

I ran git reflog, but the commit was not listed there. I also ran git fsck --lost-found, but there were no commits in the list, only a few unrelated blobs and trees.

Since I can't find any reference of the lost commit (apart from the .git/COMMIT_EDITMSG which still has the relevant commit message and list of changes), I'm not sure how to go about recovering the commit.

Is there any way to get the lost commit back, or should I get ready for an all-nighter?

解决方案

Not sure why you are unable to find your commit, as @twalberg's comment about git reset --hard is correct. Here are some things to try, though.

You have the message for the commit you're looking for (.git/COMMIT_EDITMSG). If COMMIT_EDITMSG was written, then that particular commit should be somewhere. Pick out some text from the message that is fairly unique and try this:

git log -g --grep="<something specific from your commit message>"

It will go through the reflog and find commits that match text from your lost commit's message.

If no luck with that, you can try looking through all commits on every branch:

git log --all --grep="<something specific from your commit message>"

Once you find the commit hash, you can check it out, make a new branch, merge it back into your current branch, etc.

However, if that all fails you can try looking though objects that are in the repository, but aren't part of any commit (e.g., added to the index, but not committed.) This answer can help you with that:

https://stackoverflow.com/a/7376959/845716

这篇关于重置后Git commit失败--hard。没有找到fsck,没有在reflog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆