git 如何回滚前两次提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4762906/
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
How to rollback the two previous commits?
提问by Marius Butuc
Consider this scenario:
考虑这个场景:
- Developer A does a commit: #n
- Dev. B does commit #n+1
- Dev. A does commit #n+2
- and commit #n+3
- 开发人员 A 提交:#n
- 开发。B 确实提交了#n+1
- 开发。A 确实提交#n+2
- 并提交#n+3
and then discovers that in his commit #n+2 he introduced a defect.
然后发现在他的提交 #n+2 中他引入了一个缺陷。
How can dev. A rollback his last 2 commits and continue developing on commit #n+1?
怎么可能开发。回滚他的最后 2 次提交并继续在提交#n+1 上开发?
Tried git reset --hard HEAD~2
*, but it's coming back to dev A's commit #n.
尝试过git reset --hard HEAD~2
*,但它又回到了 dev A 的提交#n。
回答by Adam Dymitruk
It should come back to the n+1 commit. You probably have a merge commit in there as well. You can also do a git reset --hard <sha1_of_where_you_want_to_be>
它应该回到 n+1 提交。您可能也有一个合并提交。你也可以做一个git reset --hard <sha1_of_where_you_want_to_be>
WARNING!!
--hard
means that any uncommitted changes you currently have will be thrown away permanently.
警告!!
--hard
意味着您当前拥有的任何未提交的更改都将被永久丢弃。