简体   繁体   English

在主分支上撤消Git

[英]Git undo on master branch

I have pushed a commit containing an error. 我已推送包含错误的提交。 I am using SourceTree. 我正在使用SourceTree。 I understand how to reset master to the previous commit (Hard), but after I do that, I cannot push anything because it says that master is one commit behind so it will not allow me to push again. 我知道如何将master重置为先前的提交(硬),但是这样做之后,我无法执行任何操作,因为它说master是后面的提交,因此不允许我再次进行推送。

How complicated it is to undo a pushed commit? 撤销推送的提交有多复杂? I tried to find a solution but no avail, is it maybe SourceTree that has a special restriction? 我试图找到一种解决方案,但无济于事,也许SourceTree受到特殊限制吗? How can I undo the pushed commit with CLI? 如何使用CLI撤消推送的提交?

You can make a new commit that reverts the faulty commit, and push that so the changes also get reverted on the remote. 您可以进行新的提交来还原错误的提交,然后推送该提交,以便更改也可以在远程上恢复。

$ git revert 43rey6w

Here 43rey6w is a madeup commit hash to illustrate what to type as command, you have to replace it with the actual hash of the commit you want to undo. 这里的43rey6w是一个伪造的提交哈希,用于说明键入命令的内容,您必须将其替换为要撤消的提交的实际哈希。

The revert command creates a new commit that undos the changes in the original commit, so you can just push it 'over' the previous commit. revert命令创建一个新的提交,该提交撤消了原始提交中的更改,因此您可以将其“推”到上一个提交上。

If you want to read more about the revert command you can check http://git-scm.com/docs/git-revert.html 如果您想了解更多有关还原命令的信息,可以查看http://git-scm.com/docs/git-revert.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM