Completely override a previous git commit
My colleague has pushed开发者_开发知识库 to our git repository a mistake. I wish to commit some updated code, but I had not git pulled and as a result am 1 commit behind the HEAD. How can I ignore his changes completely and override his mistake if I am behind?
You can force a push like the other answer suggests, but a safer way is to go ahead and pull his changes, then git revert
his commit, which will completely undo all his changes. This doesn't run the risk of unintentionally losing changes:
git pull
git revert <treeish naming his commit>
git push
I guess you mean he pushed a bad commit to a central repo.
If so, then you can push your version using git push -f
and this will override the repository. Of course, this will also break history (f
means force) so your colleague(s) will have to re-clone the central repo.
精彩评论