git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Undo a commit that is already pushed to central server and merged to several branches
@ 2011-12-07 14:15 Matthias Fechner
  2011-12-07 14:42 ` Ramkumar Ramachandra
  0 siblings, 1 reply; 6+ messages in thread
From: Matthias Fechner @ 2011-12-07 14:15 UTC (permalink / raw)
  To: Git Mailing List

Dear git list,

I commited two files into the master branch (later I figured out that 
the files included a lot bugs).

I continued to work then on different branches and merged the bad master 
branch to all my other branches.

I pushed the master branch then to the server including the bogus commit.

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.

Is this possible and how?

Bye
Matthias

-- 
"Programming today is a race between software engineers striving to 
build bigger and better idiot-proof programs, and the universe trying to 
produce bigger and better idiots. So far, the universe is winning." -- 
Rich Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo a commit that is already pushed to central server and merged to several branches
  2011-12-07 14:15 Undo a commit that is already pushed to central server and merged to several branches Matthias Fechner
@ 2011-12-07 14:42 ` Ramkumar Ramachandra
  2011-12-07 15:35   ` Matthias Fechner
  0 siblings, 1 reply; 6+ messages in thread
From: Ramkumar Ramachandra @ 2011-12-07 14:42 UTC (permalink / raw)
  To: Matthias Fechner; +Cc: Git Mailing List

Hi Matthias,

Matthias Fechner wrote:
> [...]
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo a commit that is already pushed to central server and merged to several branches
  2011-12-07 14:42 ` Ramkumar Ramachandra
@ 2011-12-07 15:35   ` Matthias Fechner
  2011-12-07 16:01     ` Ramkumar Ramachandra
  2011-12-07 16:01     ` Johan Herland
  0 siblings, 2 replies; 6+ messages in thread
From: Matthias Fechner @ 2011-12-07 15:35 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git Mailing List

Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:
> 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

that will not work, because in the master branch I already have around 
15 commits after the bogus commit and I want to keep these commits.

And in some other branches there are tons of commits (over 100) after 
the bogus commit with the merge and I only want to remove that bogus 
commit but keep all other commits after the bogus commit (all commits 
are not related to the bogus one, they are all in different files).

It is even fine if I could remove the bogus commit from all branches.

Bye
Matthias

-- 
"Programming today is a race between software engineers striving to 
build bigger and better idiot-proof programs, and the universe trying to 
produce bigger and better idiots. So far, the universe is winning." -- 
Rich Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo a commit that is already pushed to central server and merged to several branches
  2011-12-07 15:35   ` Matthias Fechner
@ 2011-12-07 16:01     ` Ramkumar Ramachandra
  2011-12-07 16:01     ` Johan Herland
  1 sibling, 0 replies; 6+ messages in thread
From: Ramkumar Ramachandra @ 2011-12-07 16:01 UTC (permalink / raw)
  To: Matthias Fechner; +Cc: Git Mailing List

Hi Matthias,

Matthias Fechner wrote:
> Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:
>
>> 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
>
>
> that will not work, because in the master branch I already have around 15
> commits after the bogus commit and I want to keep these commits.
>
> And in some other branches there are tons of commits (over 100) after the
> bogus commit with the merge and I only want to remove that bogus commit but
> keep all other commits after the bogus commit (all commits are not related
> to the bogus one, they are all in different files).

I see.  I won't attempt to repeat what Junio and Linus have explained
in this document then [1].

Cheers.

[1]: http://schacon.github.com/git/howto/revert-a-faulty-merge.txt

-- Ram

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo a commit that is already pushed to central server and merged to several branches
  2011-12-07 15:35   ` Matthias Fechner
  2011-12-07 16:01     ` Ramkumar Ramachandra
@ 2011-12-07 16:01     ` Johan Herland
  2011-12-08  9:46       ` Matthias Fechner
  1 sibling, 1 reply; 6+ messages in thread
From: Johan Herland @ 2011-12-07 16:01 UTC (permalink / raw)
  To: Matthias Fechner; +Cc: Ramkumar Ramachandra, Git Mailing List

On Wed, Dec 7, 2011 at 16:35, Matthias Fechner <idefix@fechner.net> wrote:
> Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:
>>
>> 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
>
>
> that will not work, because in the master branch I already have around 15
> commits after the bogus commit and I want to keep these commits.
>
> And in some other branches there are tons of commits (over 100) after the
> bogus commit with the merge and I only want to remove that bogus commit but
> keep all other commits after the bogus commit (all commits are not related
> to the bogus one, they are all in different files).
>
> It is even fine if I could remove the bogus commit from all branches.

Use "git revert $commit" to undo the effects of the given $commit.
This must be applied to all affected branches (either by reverting in
the master branch and remerging master to the other branches, or by
using "git revert" in each individual branch).

Note that the "git revert" command will NOT remove the original bogus
commit. Instead, it will create a new commit that undoes the changes
introduced by the bogus commit. If the same lines/files have been
touched by other commits in the meantime, you might get conflicts that
you'll have to resolve, just like a regular merge.

If you'd rather want the bogus commit to disappear entirely (i.e.
rewrite the history so that it looks like the bogus comit never
happened in the first place), then things get more complicated. You
will need to recreate the history of your master branch, skipping the
bogus commit, and then recreate all the other branches in a similar
manner. The "git rebase" tool will be helpful here, but I recommend
that you understand and get used to how it works before applying it to
this problem. Note that rewriting history is only a good idea when you
haven't shared the history with anyone else. If other people are
already using any of the branches with the bogus commit, then
rewriting the history is a BIG NO-NO. In that case, "git revert" is
the only sane approach.


Have fun! :)

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo a commit that is already pushed to central server and merged to several branches
  2011-12-07 16:01     ` Johan Herland
@ 2011-12-08  9:46       ` Matthias Fechner
  0 siblings, 0 replies; 6+ messages in thread
From: Matthias Fechner @ 2011-12-08  9:46 UTC (permalink / raw)
  To: Johan Herland; +Cc: Ramkumar Ramachandra, Git Mailing List

Dear Ramkumar and Johan,

Am 07.12.11 17:01, schrieb Johan Herland:
> Use "git revert $commit" to undo the effects of the given $commit.
> This must be applied to all affected branches (either by reverting in
> the master branch and remerging master to the other branches, or by
> using "git revert" in each individual branch).

thanks a lot for your help.
The steps I did now was at first undo everything i did locally with:
git reset --hard origin/master

Then undo the bad commit:
git revert commit-id
git commit

Now the bad commit was undone and I merged the master branch in all 
other branches.

I create a new branch and cherry-picked the bad commit into it so I can 
correct the problem there and later merge this branch in all the other ones.

Hopefully this short summary will help other users having the same problem.

Bye
Matthias

-- 
"Programming today is a race between software engineers striving to 
build bigger and better idiot-proof programs, and the universe trying to 
produce bigger and better idiots. So far, the universe is winning." -- 
Rich Cook

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-08  9:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-07 14:15 Undo a commit that is already pushed to central server and merged to several branches Matthias Fechner
2011-12-07 14:42 ` Ramkumar Ramachandra
2011-12-07 15:35   ` Matthias Fechner
2011-12-07 16:01     ` Ramkumar Ramachandra
2011-12-07 16:01     ` Johan Herland
2011-12-08  9:46       ` Matthias Fechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).