{"thread":{"id":"25937","subject":"duplicate commits after git rebase -i HEAD~10","startedAt":"2010-12-03T15:04:53Z","lastAt":"2010-12-14T16:07:31Z","messageCount":3,"participants":["Mathieu Malaterre","Jeff King","Gavin Guo"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"157213","messageId":"AANLkTi=W9MyCuOuk49AtCxR7nTa5xkddY_2HkhOvQip-@mail.gmail.com","threadId":"25937","inReplyTo":null,"subject":"duplicate commits after git rebase -i HEAD~10","fromName":"Mathieu Malaterre","fromEmail":"mathieu.malaterre@gmail.com","sentAt":"2010-12-03T15:04:53Z","receivedAt":"2010-12-03T15:04:53Z","isPatch":false,"sender":{"key":"mathieu.malaterre@gmail.com","avatar":"https://gravatar.com/avatar/0728db14da3b5f9cb00476f504394196a14dac116214d8114f402fad0871bb86?d=mp&s=160"},"body":"Hi,\n\n  I am trying to understand what I did wrong in my git rebase and\neventually I would like to repair my mistakes. Basically after a git\nrebase, I ended up with duplicate *identical* commits. One was on the\nmaster branch and one was on a local branch which was merge to master.\n\n$ git log --graph\n...\n| * commit 662be6a57a6a64840ba0f1b29d422ab6b129ff04\n| | Author:\n| | Date:   Fri Dec 3 15:27:10 2010 +0100\n| |\n| |     BUG: 122 Work toward a better framework for Java wrapping testing\n| |\n* | commit 1f639b9fd6c04eb48a69d84749bb30d7dd816382\n| | Author:\n| | Date:   Fri Dec 3 15:42:16 2010 +0100\n| |\n| |     BUG: 122 Work toward a better framework for Java wrapping testing\n| |\n\nIs there a way to properly merge identical commit back together ?\n\nThanks !\n\n-- \nMathieu\n"},{"id":"157214","messageId":"20101203153435.GA6069@sigill.intra.peff.net","threadId":"25937","inReplyTo":"AANLkTi=W9MyCuOuk49AtCxR7nTa5xkddY_2HkhOvQip-@mail.gmail.com","subject":"Re: duplicate commits after git rebase -i HEAD~10","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-12-03T15:34:35Z","receivedAt":"2010-12-03T15:34:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Dec 03, 2010 at 04:04:53PM +0100, Mathieu Malaterre wrote:\n\n>   I am trying to understand what I did wrong in my git rebase and\n> eventually I would like to repair my mistakes. Basically after a git\n> rebase, I ended up with duplicate *identical* commits. One was on the\n> master branch and one was on a local branch which was merge to master.\n\nThey're not quite identical. They may make the same logical change, but\nthey are based on different history.\n\nThe mistake you made is to rebase commits that have been published on\nanother branch. Generally you would throw away the \"originals\" after\nrebasing, but in this case, the master branch already knows about them\n(due to the merge), so that may not be an option.\n\nHow you proceed with fixing it depends on what your history looks like,\nand how much of it you are willing to rewrite. From your description,\nyour history looks something like:\n\n             F----G <-- original branch\n            /      \\\n  ...A--B--C--D--E--M <-- master\n            \\\n             F'--G' <-- rebased branch\n\nwhere F' is the commit matching F, and so forth. Due to merge M, master\ncontains the commits from the original branch, but your newly rebased\nbranch has the matching ones.\n\nIf you have not actually published the merged value of master to anyone\nelse, and you have not built anything on top of master, then it is safe\nto redo that merge, like:\n\n  git checkout master\n  git reset --hard HEAD^\n  git merge your-branch\n\nIf you have built on top of master, you can still redo the merge, but\nyou would then need to replay those new commits on top of the new merge:\n\n # make a new branch at master just before the merge; you will have to\n # find the commit id of the merge via \"git log\" or gitk\n git checkout tmp-branch M^\n\n # now redo the merge, using the rebased commits\n git merge your-branch\n\n # and now we rebase master, using just the commits from _after_ the\n # merge, on top of our re-done merge\n git rebase --onto tmp-branch M master\n\n # the rebase command leaves us on \"master\" as a side effect; we can now\n # delete tmp-branch\n git branch -d tmp-branch\n\nIf you have published your merged master for others to build on top of,\nthen you probably don't want to rewrite it, as it will cause pain for\nothers. Just live with the commits you've published, and redo your\nchanges as new commits on top. To restore the state of your-branch to\nwhat it was before the rebase, look in the reflog (\"git log -g\nyour-branch\"), then reset it (\"git checkout your-branch; git reset\n--hard your-branch@{1}\" (or whatever reflog entry looks to be correct)).\n\nYou may want to also look at this thread, which shows a similar problem,\nand in which I drew a lot more pictures, which may help explain:\n\n  http://article.gmane.org/gmane.comp.version-control.git/161823\n\n-Peff\n"},{"id":"158059","messageId":"AANLkTimSAjHOc42LOwkbFxqGEKrR0sOTcZB_mA2Ttj09@mail.gmail.com","threadId":"25937","inReplyTo":"20101203153435.GA6069@sigill.intra.peff.net","subject":"Re: duplicate commits after git rebase -i HEAD~10","fromName":"Gavin Guo","fromEmail":"tuffkidtt@gmail.com","sentAt":"2010-12-14T16:07:31Z","receivedAt":"2010-12-14T16:07:31Z","isPatch":false,"sender":{"key":"tuffkidtt@gmail.com","avatar":null},"body":"The first one:\n\n>  git checkout master\n>  git reset --hard HEAD^\n>  git merge your-branch\n\nThe second:\n\n>  git checkout tmp-branch M^\n>  git merge your-branch\n>  git rebase --onto tmp-branch M master\n>  git branch -d tmp-branch\n\nI don't exactly know what the difference between the two methods to\nsolve the duplicate problem. Why if there is already a built under\nmaster need to use the second solution? It seems the same to me to\nsolve the problem.\n\nGavin Guo\n"}]}