git - 还原交互式 git rebase

标签 git git-rebase

完成功能分支后,在 git rebase -i 期间,我不小心删除了所有提交。我不完全确定,但我怀疑我没有压缩我的提交,而是用提交消息替换了整个条目。

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,你可以试试mentioned here :

git reset --hard ORIG_HEAD

作为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).

如果您 rebase 后执行了一些操作,reflog can still help .

关于git - 还原交互式 git rebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5375066/

相关文章:

git - SSH 无法确定 [server] 的真实性

git - 我不小心在 master 上工作,如何将我对分支重置 master 所做的所有更改转移到最后一次提交?

Git add 和 git commit 混淆

java - Egit 工作目录与 Eclipse 中的项目

git - 为什么 git rebase 覆盖我的本地更改?如何避免覆盖?

git - 如何为 Bitbucket 创建 GitHub 镜像?

Git rebase 一次又一次地回到同一个地方

Git merge 单个文件而无需 rebase

git - 解决大型项目团队中的冲突

git - git rebase --onto --preserve-merges再现了我已经在 merge 中解决的冲突