{"thread":{"id":"25049","subject":"git rebase --preserve-merges seems to not work","startedAt":"2010-09-09T05:17:39Z","lastAt":"2010-09-09T06:26:42Z","messageCount":3,"participants":["Joshua Jensen","Björn Steinbrink"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"150348","messageId":"4C886DF3.8050903@workspacewhiz.com","threadId":"25049","inReplyTo":null,"subject":"git rebase --preserve-merges seems to not work","fromName":"Joshua Jensen","fromEmail":"jjensen@workspacewhiz.com","sentAt":"2010-09-09T05:17:39Z","receivedAt":"2010-09-09T05:17:39Z","isPatch":false,"sender":{"key":"jjensen@workspacewhiz.com","avatar":"https://avatars.githubusercontent.com/u/111687?v=4"},"body":"  In order to push changes to our master branch, one has to have pulled \nfirst.  We pull with the --rebase option.  It works great except for \nmerge commits.\n\nI discovered 'git rebase' has a --preserve-merges option.  I assumed it \nwould allow me to rebase my merge commit on top of others' changes \npushed to our central master branch.\n\nUnfortunately, I can't seem to make it work.  Does anyone have thoughts \non what I'm doing wrong?\n\nMy session is below.\n\nThanks!\n\nJosh\n\n\n$ git init\n\n$ echo a > a\n$ git add a\n$ git commit -m a\n$ git tag a\n\n$ echo b > b\n$ git add b\n$ git commit -m b\n\n$ echo c > c\n$ git add c\n$ git commit -m c\n$ git tag c\n\n# Note the hierarchy is simple: a <- b <- c\n$ git lg --all\n* d132c87 - (c) c\n* 4a88fd1 - b\n* b576660 - (a) a\n\n\n# Create the hierarchy: a <- d\n$ git checkout a\nNote: checking out 'a'.\n\n$ echo d > d\n$ git add d\n$ git commit -m d\n$ git tag d\n\n$ git lg --all\n* 6abf527 - (HEAD, d) d\n| * d132c87 - (c) c\n| * 4a88fd1 - b\n|/\n* b576660 - (a) a\n\n\n# Wanting to merge my branch back to my local master to push to the server.\n$ git checkout a\n$ git merge --no-ff c\nMerge made by recursive.\n  b |    1 +\n  c |    1 +\n  2 files changed, 2 insertions(+), 0 deletions(-)\n  create mode 100644 b\n  create mode 100644 c\n$ git tag bc-merge\n\n\n# Commit 'd' is something I would pull --rebase from the server before I \npush.\n$ git lg --all\n*   472fd93 - (HEAD, bc-merge) Merge commit 'c' into HEAD (3 seconds ago)\n|\\\n| * d132c87 - (c) c (2 minutes ago)\n| * 4a88fd1 - b (2 minutes ago)\n|/\n| * 6abf527 - (d) d (2 minutes ago)\n|/\n* b576660 - (a, master) a (3 minutes ago)\n\n\n# Here is the rebase with the --preserve-merges option.\n$ git rebase --preserve-merges d\nRebasing (n/3)\nSuccessfully rebased and updated detached HEAD.\n\n# Of course, bc-merge is an orphaned branch.  Its changes got replayed \non top of 'd'.\n# Note the merge commit with the description \"Merge commit 'c' into \nHEAD\" is missing.\n$ git lg --all\n* 2c93a8a - (HEAD) c (11 seconds ago)\n* 2b98bc6 - b (11 seconds ago)\n* 6abf527 - (d) d (3 minutes ago)\n| *   472fd93 - (bc-merge) Merge commit 'c' into HEAD (74 seconds ago)\n| |\\\n|/ /\n| * d132c87 - (c) c (3 minutes ago)\n| * 4a88fd1 - b (3 minutes ago)\n|/\n* b576660 - (a, master) a (4 minutes ago)\n"},{"id":"150352","messageId":"20100909055104.GA21004@atjola.homenet","threadId":"25049","inReplyTo":"4C886DF3.8050903@workspacewhiz.com","subject":"Re: git rebase --preserve-merges seems to not work","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2010-09-09T05:51:04Z","receivedAt":"2010-09-09T05:51:04Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2010.09.08 23:17:39 -0600, Joshua Jensen wrote:\n> # Commit 'd' is something I would pull --rebase from the server\n> before I push.\n> $ git lg --all\n> *   472fd93 - (HEAD, bc-merge) Merge commit 'c' into HEAD (3 seconds ago)\n> |\\\n> | * d132c87 - (c) c (2 minutes ago)\n> | * 4a88fd1 - b (2 minutes ago)\n> |/\n> | * 6abf527 - (d) d (2 minutes ago)\n> |/\n> * b576660 - (a, master) a (3 minutes ago)\n> \n> \n> # Here is the rebase with the --preserve-merges option.\n> $ git rebase --preserve-merges d\n> Rebasing (n/3)\n> Successfully rebased and updated detached HEAD.\n> \n> # Of course, bc-merge is an orphaned branch.  Its changes got\n> replayed on top of 'd'.\n\nYup, and the \"problem\" is, that both sides of the merge got replayed.\n\n> # Note the merge commit with the description \"Merge commit 'c' into\n> HEAD\" is missing.\n\nBecause the merge could be resolved as a fast-forward, as it merges the\nreplayed commits b' and c', not the originals.\n\n> $ git lg --all\n> * 2c93a8a - (HEAD) c (11 seconds ago)\n> * 2b98bc6 - b (11 seconds ago)\n> * 6abf527 - (d) d (3 minutes ago)\n> | *   472fd93 - (bc-merge) Merge commit 'c' into HEAD (74 seconds ago)\n> | |\\\n> |/ /\n> | * d132c87 - (c) c (3 minutes ago)\n> | * 4a88fd1 - b (3 minutes ago)\n> |/\n> * b576660 - (a, master) a (4 minutes ago)\n\nWhat you actually wanted to replay is just the first-parent history,\nredoing the merges with their respective original second parent.\nJonathan (Cc'ed) had the same problem about a month ago.\n\nThe \"first parent\" thing isn't that well defined, criss-cross merges\ncombined with some unfortunate fast-forwards will easily make the\nfirst-parent history become the one that you didn't mean (ask any\ngit-svn users that dared to use \"git merge\" without fully understanding\nhow git-svn uses the history ;-)), but it works in this special case.\nAnd with that special case in mind (and admittedly probably not thinking\nmuch further) I came up with this patch a few years ago:\n\nhttp://marc.info/?l=git&m=119379735525213&w=2\n\nIt was not my itch to scratch though, so I never got around to get it\nincluded, and of course it doesn't apply cleanly anymore. I tried to\ngive some hints to Jonathan (\"hachi\") on #git on how to update the patch\nto make it apply again:\n\nhttp://colabti.de/irclogger/irclogger_log/git?date=2010-08-20#l1241\n\nFeel free to pick up from there...\n\nBjörn\n"},{"id":"150355","messageId":"4C887E22.5050303@workspacewhiz.com","threadId":"25049","inReplyTo":"20100909055104.GA21004@atjola.homenet","subject":"Re: git rebase --preserve-merges seems to not work","fromName":"Joshua Jensen","fromEmail":"jjensen@workspacewhiz.com","sentAt":"2010-09-09T06:26:42Z","receivedAt":"2010-09-09T06:26:42Z","isPatch":false,"sender":{"key":"jjensen@workspacewhiz.com","avatar":"https://avatars.githubusercontent.com/u/111687?v=4"},"body":"  ----- Original Message -----\nFrom: Björn Steinbrink\nDate: 9/8/2010 11:51 PM\n>> $ git lg --all\n>> * 2c93a8a - (HEAD) c (11 seconds ago)\n>> * 2b98bc6 - b (11 seconds ago)\n>> * 6abf527 - (d) d (3 minutes ago)\n>> | *   472fd93 - (bc-merge) Merge commit 'c' into HEAD (74 seconds ago)\n>> | |\\\n>> |/ /\n>> | * d132c87 - (c) c (3 minutes ago)\n>> | * 4a88fd1 - b (3 minutes ago)\n>> |/\n>> * b576660 - (a, master) a (4 minutes ago)\n> What you actually wanted to replay is just the first-parent history,\n> redoing the merges with their respective original second parent.\n> Jonathan (Cc'ed) had the same problem about a month ago.\n>\n> The \"first parent\" thing isn't that well defined, criss-cross merges\n> combined with some unfortunate fast-forwards will easily make the\n> first-parent history become the one that you didn't mean (ask any\n> git-svn users that dared to use \"git merge\" without fully understanding\n> how git-svn uses the history ;-)), but it works in this special case.\n> And with that special case in mind (and admittedly probably not thinking\n> much further) I came up with this patch a few years ago:\n>\n> http://marc.info/?l=git&m=119379735525213&w=2\nI hand merged your change in to my Git installation.  There is one part \nof git-rebase--interactive that looks entirely different, so I would \nneed to look back through the history to determine how to properly apply it.\n\nThe good news is the patch does exactly what I want in this simple \ncase.  I will have to try it on some more complicated hierarchies to see \nwhat the end result is.\n\nIt's curious... whenever I ask around about issue X or feature Y, a \npreviously submitted patch can generally be found in the list archives.  :)\n\nJosh\n"}]}