Problem
You were a bit hasty and committed and pushed something you should not have, e.g., as it has happened to me, into the wrong branch. Now, you want to undo the commit also in the remote repository, but not loose the changes you made.
Solution
Technically, you want, to my understanding
- Make HEAD point to the previous commit.
- Clean the index from the wrong commit.
- Push to the remote repository.
$ git reset --mixed HEAD~
where ~ stands for the parent commit, to go back more than commit, issue multiple times. The mixed option is the standard and therewith optional.git push
And this is the rather tricky part, because git might to refuse. In that case, you have two potentially dangerous options and you might want to double check withgit help push
I presume if you are on your own branch and nobody is working on it (as it should be?), you are safe with any of the options. Please don't sue me.--force-with-lease
This will overwrite the changes others are pushing while you are pushing (at least that is what I have understood).--force
This will overwrite ALL changes others might have pushed inbetween your wrong commit and this fixing.
No comments:
Post a Comment