简体   繁体   中英

Git undo on master branch

I have pushed a commit containing an error. I am using 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.

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? How can I undo the pushed commit with 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.

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.

If you want to read more about the revert command you can check http://git-scm.com/docs/git-revert.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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