恢复交互式 git rebase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5375066/
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
Reverting an interactive git rebase
提问by Zubin
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.
在完成一个功能分支后,git rebase -i
我不小心删除了我所有的提交。我不完全确定,但我怀疑不是压缩我的提交,而是用提交消息替换了整个条目。
http://shafiulazam.com/gitbook/4_interactive_rebasing.htmlsays:
http://shafiulazam.com/gitbook/4_interactive_rebasing.html说:
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.
交互式 rebase 可以做的最后一件有用的事情是为您删除提交。如果不是为提交行选择“pick”、“squash”或“edit”,而是简单地删除该行,它将从历史记录中删除提交。
My question is: is there a way to revert/undo this?
我的问题是:有没有办法恢复/撤消这个?
回答by VonC
If you have just done the rebase, you can try as mentioned here:
如果你刚刚完成了 rebase,你可以尝试这里提到的:
git reset --hard ORIG_HEAD
ORIG_HEAD
is previous state ofHEAD
, 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 toORIG_HEAD
(HEAD@{1}
is always last value ofHEAD
,ORIG_HEAD
is last value ofHEAD
before dangerous operation).
ORIG_HEAD
是 的先前状态HEAD
,由可能具有危险行为的命令设置,以便于恢复它们。
现在 Git 有 reflog 的用处不大:HEAD@{1}
大致相当于ORIG_HEAD
(HEAD@{1}
总是最后一个值HEAD
,ORIG_HEAD
是HEAD
危险操作之前的最后一个值)。
If you have executed some operations sincethe rebase, the reflogcan still help.
如果已执行某些操作,因为在底垫中,引用日志仍然可以帮助。
回答by Philipp T.
You can do "git reflog" and get back your old HEAD.
您可以执行“git reflog”并取回旧的 HEAD。