Reputation: 4715
Ive made a bit of a mess of my repo.
Ive made some changes & pushed them up to the repo & now id like to undo that. (i merged things all wrong)
On my local machine I have done that with the following command:
git reset --hard 72a535b
Which seems to have done the trick. Then i implemented the changes correctly, committed them & attempted to push.
Of course thats failed with error
denying non-fast0forward refs/heads/master (you should pull first)
which i don't think i want to do, as then ill lose my changes and be back to the 1st set of broken mods.
how can i sort this horrible mess out?
Upvotes: 3
Views: 2663
Reputation: 3315
Your best and safe option is
git revertOK, it create and extra commit and your bad commit stays for life. Buy why care. As long as top of branch is clean why hide past mistakes.
Upvotes: 1
Reputation: 164341
Assuming no-one has pulled your "bad" changes yet, force the push:
git push -f
The server rejects the normal push, because it would cause the serverside repo to lose changes (your mess). In this case, this seems to be what you want, so go ahead and force it. Just be aware that forcing a push is in general a dangerous thing to do, because you can lose history.
It can get messy if other users has already pulled your changes, because then they will have to resolve the conflicts in a meaningful way before they can push. So if you have any collaborators on the project, be sure to check if they have already got your copy of the code, and if they do, warn them about what you are about to do and make sure they pull the right version as soon as it is available.
Upvotes: 7