Reputation: 45263
I know this question has been asked before but although the given answer git reset --hard HEAD~1
works, I cannot push it to the server since the server is ahead. Pulling obviously puts me right back where I was.
How do I reset the server?
Upvotes: 3
Views: 19201
Reputation: 8029
You want to force a push. Only use this if you are certain of the change.
git push origin --force
Upvotes: 3
Reputation: 6507
It all depends on the project's conventions. The safe bet is to use git revert
because you can always drop the commit later if that's the policy. If you want to revert a merge, you need to specify which parent you want to revert to ("mainline") with git revert --mainline <parent-number>
.
You should ask the project's maintainer to explain what to do in your specific case.
In our team, we use the following set of rules:
branch.autosetuprebase=always
)master
is the only "public" branchThis means everybody is free to do whatever they wish with their private branches, you can rebase or drop commits as you feel fit. On the other hand, our shared server is configured to refuse forced pushes to master.
That is not to say we never reset master, sometimes (maybe once a year) someone might accidentally push a merge where we think that it would terribly screw up our history. In these exceptional cases one of our git-gurus will write an email to the whole team, explaining what is about to happen and what steps to take to update local clones.
Upvotes: 5
Reputation: 1328562
Force pushing is an option, if your colleagues accepts to reset their own local branch to the new origin/master (assuming we are talking about that 'master' branch).
git fetch
git reset origin/master
(not a reset --hard
, because that would wipe out work in progress and private file)
(note that it will unstage whatever was already added to the index)
The other option, "to undo your cock ups" (if you have already pushed the wrong commit), it to revert it, creating a new one which cancel the previous one.
See git revert
.
You can then push (regular push) that revert commit.
Upvotes: 2