Git 取消恢复
在 git 中,假设我提交了 A 和 B
A---[B]
但随后我恢复了
git revert HEAD
所以我现在就在那里:
[A]---B
如何取消我的恢复以便我可以返回到 B?
In git let say I commit A and 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您有两个一般选择:
仅当您未将更改推送到其他任何地方时,第二个选项才适用。事实上,如果您还没有将第一个恢复提交推送到任何地方,您可以简单地使用
在不创建任何恢复提交的情况下回滚。
You have two general choices:
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
to roll back without creating any revert commits at all.
如果您还没有完全完成,即在 gitbash 中您看到类似以下内容:
那么您可以使用 git revert --abort 来中止。
如果您已经完成了......只是不要硬重置,更改仍然存在。使用 git reset --soft 恢复提交但保留更改。
另外,如果你想恢复超过 1 次提交:
现在我不再在终端中做事,而是依赖 Intellij IDEA。实际上,在选择一个提交并“将当前分支重置到此处...”后,我从 IDEA 中的这个对话框中了解了软重置与硬重置之间的区别:
非常清晰的解释。
If you haven't done it completely, i.e., in
gitbash
you see something like:then you can use
git revert --abort
to abort.If you have done it.. just don't hard reset, the changes are still there. Use
git reset --soft
to revert commit but keeping changes.Also, if you want to revert more than 1 commits:
Nowadays I stop doing things in terminal and I rely on Intellij IDEA. Actually I learnt the difference between soft vs. hard reset from this dialog in IDEA after selecting one commit and "Reset current branch to here...":
Very clear explanations.
当您创建一个新的
提交
(它恢复另一个提交
)时,您可以将其视为正常提交。所以基本上你有很多选择,比如
As you create a new
commit
whichreverts another commit
you can treat it like a normal commit.So basically you have many choices, such as
你能做的就是“挑选”原始提交并再次推送。
What you can do is "cherry-pick" original commit and push again.