{"thread":{"id":"29104","subject":"Undo a commit that is already pushed to central server and merged to several branches","startedAt":"2011-12-07T14:15:08Z","lastAt":"2011-12-08T09:46:26Z","messageCount":6,"participants":["Matthias Fechner","Ramkumar Ramachandra","Johan Herland"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"180479","messageId":"4EDF74EC.6090504@fechner.net","threadId":"29104","inReplyTo":null,"subject":"Undo a commit that is already pushed to central server and merged to several branches","fromName":"Matthias Fechner","fromEmail":"idefix@fechner.net","sentAt":"2011-12-07T14:15:08Z","receivedAt":"2011-12-07T14:15:08Z","isPatch":false,"sender":{"key":"idefix@fechner.net","avatar":"https://gravatar.com/avatar/3bbc5542677a77cb9b75262e4ad2eeb04a0960f0b8dec89a178db17cf472cce7?d=mp&s=160"},"body":"Dear git list,\n\nI commited two files into the master branch (later I figured out that \nthe files included a lot bugs).\n\nI continued to work then on different branches and merged the bad master \nbranch to all my other branches.\n\nI pushed the master branch then to the server including the bogus commit.\n\nWhat I would like to do is move this bogus commit into a different \nbranch and remove all changes from this bogus commit from every branch.\n\nIs this possible and how?\n\nBye\nMatthias\n\n-- \n\"Programming today is a race between software engineers striving to \nbuild bigger and better idiot-proof programs, and the universe trying to \nproduce bigger and better idiots. So far, the universe is winning.\" -- \nRich Cook\n"},{"id":"180481","messageId":"CALkWK0k46HnWTHx3iYuWFUegTgZhAMShx9MT2E83QCmxrvZOxg@mail.gmail.com","threadId":"29104","inReplyTo":"4EDF74EC.6090504@fechner.net","subject":"Re: Undo a commit that is already pushed to central server and merged to several branches","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-12-07T14:42:22Z","receivedAt":"2011-12-07T14:42:22Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Matthias,\n\nMatthias Fechner wrote:\n> [...]\n> I continued to work then on different branches and merged the bad master\n> branch to all my other branches.\n> [...]\n>\n> What I would like to do is move this bogus commit into a different branch\n> and remove all changes from this bogus commit from every branch.\n\nIf I understand correctly, each of your branches looks like*:\n\no  <--- HEAD of branch; merge commit referencing bogus commit\n| \\\no  \\   <--- This is where you want to move the HEAD to\n|   \\\no    o  <-- Bogus commit from master branch\n|\no\n|\no  <-- Branch born\n\nAssuming that you actually want to rewrite the history, the situation\ncalls for a git-reset(1).  Just \"git reset --hard HEAD~1\" on each of\nyour branches (Caution: first understand what it does!) and you'll\nrewind the HEAD to \"undo\" the bad merge.  After that you can just \"git\npush +foo:foo\" to overwrite the foo branch on your server.  If you\ndon't want to rewrite anything and simply commit the inverse of the\nbad commit, see git-revert(1).\n\n* If you're having difficulty understanding the diagram, please read:\nhttp://eagain.net/articles/git-for-computer-scientists/\n\nCheers.\n\n-- Ram\n"},{"id":"180487","messageId":"4EDF87A6.4000703@fechner.net","threadId":"29104","inReplyTo":"CALkWK0k46HnWTHx3iYuWFUegTgZhAMShx9MT2E83QCmxrvZOxg@mail.gmail.com","subject":"Re: Undo a commit that is already pushed to central server and merged to several branches","fromName":"Matthias Fechner","fromEmail":"idefix@fechner.net","sentAt":"2011-12-07T15:35:02Z","receivedAt":"2011-12-07T15:35:02Z","isPatch":false,"sender":{"key":"idefix@fechner.net","avatar":"https://gravatar.com/avatar/3bbc5542677a77cb9b75262e4ad2eeb04a0960f0b8dec89a178db17cf472cce7?d=mp&s=160"},"body":"Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:\n> Assuming that you actually want to rewrite the history, the situation\n> calls for a git-reset(1).  Just \"git reset --hard HEAD~1\" on each of\n> your branches (Caution: first understand what it does!) and you'll\n\nthat will not work, because in the master branch I already have around \n15 commits after the bogus commit and I want to keep these commits.\n\nAnd in some other branches there are tons of commits (over 100) after \nthe bogus commit with the merge and I only want to remove that bogus \ncommit but keep all other commits after the bogus commit (all commits \nare not related to the bogus one, they are all in different files).\n\nIt is even fine if I could remove the bogus commit from all branches.\n\nBye\nMatthias\n\n-- \n\"Programming today is a race between software engineers striving to \nbuild bigger and better idiot-proof programs, and the universe trying to \nproduce bigger and better idiots. So far, the universe is winning.\" -- \nRich Cook\n"},{"id":"180492","messageId":"CALkWK0msjfebnE=q_ykx3+iVkeT2aa1A2BmtrHCw2wGaZzOC8w@mail.gmail.com","threadId":"29104","inReplyTo":"4EDF87A6.4000703@fechner.net","subject":"Re: Undo a commit that is already pushed to central server and merged to several branches","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-12-07T16:01:03Z","receivedAt":"2011-12-07T16:01:03Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Matthias,\n\nMatthias Fechner wrote:\n> Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:\n>\n>> Assuming that you actually want to rewrite the history, the situation\n>> calls for a git-reset(1).  Just \"git reset --hard HEAD~1\" on each of\n>> your branches (Caution: first understand what it does!) and you'll\n>\n>\n> that will not work, because in the master branch I already have around 15\n> commits after the bogus commit and I want to keep these commits.\n>\n> And in some other branches there are tons of commits (over 100) after the\n> bogus commit with the merge and I only want to remove that bogus commit but\n> keep all other commits after the bogus commit (all commits are not related\n> to the bogus one, they are all in different files).\n\nI see.  I won't attempt to repeat what Junio and Linus have explained\nin this document then [1].\n\nCheers.\n\n[1]: http://schacon.github.com/git/howto/revert-a-faulty-merge.txt\n\n-- Ram\n"},{"id":"180493","messageId":"CALKQrgcQ5jv+oDXxDoTGUhmP-Dg344-oSotb+q-4a3fnEBY1Zw@mail.gmail.com","threadId":"29104","inReplyTo":"4EDF87A6.4000703@fechner.net","subject":"Re: Undo a commit that is already pushed to central server and merged to several branches","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2011-12-07T16:01:22Z","receivedAt":"2011-12-07T16:01:22Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Wed, Dec 7, 2011 at 16:35, Matthias Fechner <idefix@fechner.net> wrote:\n> Am 07.12.11 15:42, schrieb Ramkumar Ramachandra:\n>>\n>> Assuming that you actually want to rewrite the history, the situation\n>> calls for a git-reset(1).  Just \"git reset --hard HEAD~1\" on each of\n>> your branches (Caution: first understand what it does!) and you'll\n>\n>\n> that will not work, because in the master branch I already have around 15\n> commits after the bogus commit and I want to keep these commits.\n>\n> And in some other branches there are tons of commits (over 100) after the\n> bogus commit with the merge and I only want to remove that bogus commit but\n> keep all other commits after the bogus commit (all commits are not related\n> to the bogus one, they are all in different files).\n>\n> It is even fine if I could remove the bogus commit from all branches.\n\nUse \"git revert $commit\" to undo the effects of the given $commit.\nThis must be applied to all affected branches (either by reverting in\nthe master branch and remerging master to the other branches, or by\nusing \"git revert\" in each individual branch).\n\nNote that the \"git revert\" command will NOT remove the original bogus\ncommit. Instead, it will create a new commit that undoes the changes\nintroduced by the bogus commit. If the same lines/files have been\ntouched by other commits in the meantime, you might get conflicts that\nyou'll have to resolve, just like a regular merge.\n\nIf you'd rather want the bogus commit to disappear entirely (i.e.\nrewrite the history so that it looks like the bogus comit never\nhappened in the first place), then things get more complicated. You\nwill need to recreate the history of your master branch, skipping the\nbogus commit, and then recreate all the other branches in a similar\nmanner. The \"git rebase\" tool will be helpful here, but I recommend\nthat you understand and get used to how it works before applying it to\nthis problem. Note that rewriting history is only a good idea when you\nhaven't shared the history with anyone else. If other people are\nalready using any of the branches with the bogus commit, then\nrewriting the history is a BIG NO-NO. In that case, \"git revert\" is\nthe only sane approach.\n\n\nHave fun! :)\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"180569","messageId":"4EE08772.3070703@fechner.net","threadId":"29104","inReplyTo":"CALKQrgcQ5jv+oDXxDoTGUhmP-Dg344-oSotb+q-4a3fnEBY1Zw@mail.gmail.com","subject":"Re: Undo a commit that is already pushed to central server and merged to several branches","fromName":"Matthias Fechner","fromEmail":"idefix@fechner.net","sentAt":"2011-12-08T09:46:26Z","receivedAt":"2011-12-08T09:46:26Z","isPatch":false,"sender":{"key":"idefix@fechner.net","avatar":"https://gravatar.com/avatar/3bbc5542677a77cb9b75262e4ad2eeb04a0960f0b8dec89a178db17cf472cce7?d=mp&s=160"},"body":"Dear Ramkumar and Johan,\n\nAm 07.12.11 17:01, schrieb Johan Herland:\n> Use \"git revert $commit\" to undo the effects of the given $commit.\n> This must be applied to all affected branches (either by reverting in\n> the master branch and remerging master to the other branches, or by\n> using \"git revert\" in each individual branch).\n\nthanks a lot for your help.\nThe steps I did now was at first undo everything i did locally with:\ngit reset --hard origin/master\n\nThen undo the bad commit:\ngit revert commit-id\ngit commit\n\nNow the bad commit was undone and I merged the master branch in all \nother branches.\n\nI create a new branch and cherry-picked the bad commit into it so I can \ncorrect the problem there and later merge this branch in all the other ones.\n\nHopefully this short summary will help other users having the same problem.\n\nBye\nMatthias\n\n-- \n\"Programming today is a race between software engineers striving to \nbuild bigger and better idiot-proof programs, and the universe trying to \nproduce bigger and better idiots. So far, the universe is winning.\" -- \nRich Cook\n"}]}