reverting push'd git commit

天大地大妈咪最大 提交于 2019-11-30 09:02:29

The git reset --hard [sha] will correct the branch on your local repository. To force this push to work, you can do a git push origin +master:master. The + sign will force the non-linear push to work.

If the other developers have already pulled you wrong commit, they will have to do a git remote update, then a git reset --hard origin/master (provided that they are on their master branch, and have not made any other commits.

Please use these commands with some caution :-). Good luck.

FelipeFG's answer works fine in a two-developer context where you can easily coordinate redoing the other guy's local repository, but you're actually better off using git revert -m<parent id of mainline branch, 1 in this case> <commit ref>. Then, when you're finished fixing it, just git revert <revert commit>, and git merge dev (it's important to revert your revert for this case, because otherwise git merge dev will not consider your old merge an ancestor, and this will lead to conflicts that have to be resolved).

The history will be ugly, but it will also support fast-forwarding, and you won't have to worry about some poor sap untangling a mess of local conflicts thanks to your history revision.

See http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/howto/revert-a-faulty-merge.txt for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!