Lost my commit in GIT. Can you accidentally delete commits?

a 夏天 提交于 2019-12-04 20:19:57

问题


I'm using git gui and I can't see my branch.

I know I checked something in today.

I changed to an earlier branch after I did my commit and verified it with the branch viewer. I made changes to the earlier branch and then wanted to go back to my current branch, but I can't see it any more. Any help would be great.


回答1:


In answer to your question, in most circumstances it is very hard to lose a recent commit by accident. Usually objects (including commits) only get removed after a git gc if they are no longer referred to by any branch and they are very old (by default 90 days IIRC).

Usually you can find the commit in your reflog. Try either of:

git log -g

or:

git reflog

If you can see it, it probably has a reference of the form HEAD@{n} where n is the number if times your HEAD has changed since the commit you've lost.

You can create a branch for it.

git branch foundit HEAD@{n}  # replace n with the correct number

Then you can decide if you need to merge it in to another branch or rebase it or just keep the branch around for later.



来源:https://stackoverflow.com/questions/2495978/lost-my-commit-in-git-can-you-accidentally-delete-commits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!