撤消在 GIT 中压缩提交时犯的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10260151/
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
Undo a Mistake made while squashing the commits in GIT
提问by CuriousMind
I wanted to squash my last 2 commits into one, so did a git rebase, in following way:
我想通过git rebase以下方式将我的最后 2 个提交压缩为一个,a 也是如此:
git rebase -i HEAD~2
but due to a typo, what I actuallyended up pushing into origin was:
但由于打字错误,我实际上最终推入了原点:
git rebase -i HEAD-3
Now, in the Github Pull Requestit shows commit of some other unrelated commit. so basically, I want to remove commit 06674f0which isn't mine, while keeping fcea5e0in this PR.
现在,在Github Pull Request 中,它显示了其他一些无关提交的提交。所以基本上,我想删除06674f0不是我的提交,同时保留fcea5e0这个 PR。
how to fix the mess caused by simple typo?
如何修复由简单的错字造成的混乱?
回答by ralphtheninja
Edit: Check your reflog with
编辑:检查您的 reflog
git reflog
Pick the commit previous to your first rebase and replace the x with appropriate number below:
选择第一次 rebase 之前的提交,并用下面的适当数字替换 x:
Just undo your last rebase and redo it:
只需撤消您的最后一次变基并重做即可:
git reset --hard HEAD@{x}
git rebase -i HEAD~2
..
git push -f origin master
Remove your pull request and issue a new one.
删除您的拉取请求并发出一个新请求。
回答by Naresh Mehta
Both git reset --hard HEAD{x}and git reset --hard HEAD@{x}didn't work for me.
双方git reset --hard HEAD{x}并git reset --hard HEAD@{x}没有对我来说有效。
I wanted a script to do this anyways, so I did the following.
无论如何,我想要一个脚本来执行此操作,因此我执行了以下操作。
BACK_2_SHA=`git reflog show --pretty=format:'%H' -n x | tail -n 1`
git reset --hard $BACK_2_SHA

