Re: Undo a commit that is already pushed to central server and merged to several branches
- From
Ramkumar Ramachandra <artagnon@gmail.com>
- Date
- Dec 7, 2011, 14:42 UTC
- Message-ID
- <CALkWK0k46HnWTHx3iYuWFUegTgZhAMShx9MT2E83QCmxrvZOxg@mail.gmail.com>
- In-Reply-To
- <4EDF74EC.6090504@fechner.net>
Hi Matthias,
Matthias Fechner wrote:
Show 7 quoted lines
> [...] > I continued to work then on different branches and merged the bad master > branch to all my other branches. > [...] > > What I would like to do is move this bogus commit into a different branch > and remove all changes from this bogus commit from every branch.
If I understand correctly, each of your branches looks like*:
o <--- HEAD of branch; merge commit referencing bogus commit | \ o \ <--- This is where you want to move the HEAD to | \ o o <-- Bogus commit from master branch | o | o <-- Branch born
Assuming that you actually want to rewrite the history, the situation calls for a git-reset(1). Just "git reset --hard HEAD~1" on each of your branches (Caution: first understand what it does!) and you'll rewind the HEAD to "undo" the bad merge. After that you can just "git push +foo:foo" to overwrite the foo branch on your server. If you don't want to rewrite anything and simply commit the inverse of the bad commit, see git-revert(1).
* If you're having difficulty understanding the diagram, please read: http://eagain.net/articles/git-for-computer-scientists/
Cheers.
-- Ram