Reverting an interactive git rebase

不羁的心 提交于 2019-12-08 23:09:22

问题


After completing a feature branch, during a git rebase -i I accidentally removed all my commits. I'm not completely sure but I suspect that instead of squashing my commits, I replaced the entire entry with a commit message.

http://shafiulazam.com/gitbook/4_interactive_rebasing.html says:

The last useful thing that interactive rebase can do is drop commits for you. If instead of choosing 'pick', 'squash' or 'edit' for the commit line, you simply remove the line, it will remove the commit from the history.

My question is: is there a way to revert/undo this?


回答1:


If you have just done the rebase, you can try as mentioned here:

git reset --hard ORIG_HEAD

as Jakub Narębski details:

ORIG_HEAD is previous state of HEAD, set by commands that have possibly dangerous behavior, to be easy to revert them.
It is less useful now that Git has reflog: HEAD@{1} is roughly equivalent to ORIG_HEAD (HEAD@{1} is always last value of HEAD, ORIG_HEAD is last value of HEAD before dangerous operation).

If you have executed some operations since the rebase, the reflog can still help.




回答2:


You can do "git reflog" and get back your old HEAD.



来源:https://stackoverflow.com/questions/5375066/reverting-an-interactive-git-rebase

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