I\'ve got a repo with two branches-- master and dev. I was working on the master branch and pulled, and got a message that the repo was up to date. I committed my changes, a
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.
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.