git Git取消还原
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3199366/
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
Git cancel a revert
提问by mathk
In git let say I commit A and B
在 git 中假设我提交了 A 和 B
A---[B]
But then I revert with
但后来我恢复了
git revert HEAD
So I am there now:
所以我现在在那里:
[A]---B
How do I cancel my revert so that I can go back to B?
如何取消我的还原以便我可以返回 B?
回答by Greg Hewgill
You have two general choices:
您有两个常规选择:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
- 还原还原提交(创建第二个还原提交,将您带回原始提交)
- 扔掉恢复提交
git reset --hard HEAD^
git reset --hard HEAD^
The second option is only appropriate if you have notpushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
仅当您没有将更改推送到其他任何地方时,第二个选项才适用。事实上,如果你还没有在任何地方推送你的第一次还原提交,你可以简单地使用
git reset --hard
git reset --hard
to roll back without creating any revert commits at all.
回滚而不创建任何还原提交。
回答by WesternGun
If you haven't done it completely, i.e., in gitbash
you see something like:
如果您还没有完全完成,即,gitbash
您会看到以下内容:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
然后你可以使用git revert --abort
中止。
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
如果你已经完成了......只是不要重置,更改仍然存在。使用git reset
改变的状态。代替--hard
,您还可以使用--soft
(保留所有更改)。
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
回答by elp
As you create a new commit
which reverts another commit
you can threat it like a commit.
当您创建一个新的时commit
,reverts another commit
您可以像提交一样威胁它。
So basically you have many choices, such as
所以基本上你有很多选择,比如
git rebase -i
(remove the revert commit)git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)git reset --soft <commitID>
(same as above but keeps local changes)- technically you can use
git revert <commitId>
to revert your revert
git rebase -i
(删除还原提交)git reset --hard <commitID>
(在还原之前重置为提交,您将丢失所有本地更改)git reset --soft <commitID>
(同上,但保持本地变化)- 从技术上讲,您可以
git revert <commitId>
用来还原您的还原