{"thread":{"id":"34642","subject":"[RFC] allow git pull to preserve merges","startedAt":"2013-08-08T17:38:11Z","lastAt":"2013-08-09T15:28:27Z","messageCount":9,"participants":["Stephen Haberman","Johannes Schindelin","Philip Oakley","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"224833","messageId":"1375983492-32282-1-git-send-email-stephen@exigencecorp.com","threadId":"34642","inReplyTo":null,"subject":"[RFC] allow git pull to preserve merges","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-08T17:38:11Z","receivedAt":"2013-08-08T17:38:11Z","isPatch":false,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"Hey,\n\nFollowing up on an old thread (2008):\n\nhttp://git.661346.n2.nabble.com/pull-preserve-merges-td1471688.html\n\nI'd like to finally add a config parameter/setting to allow git pull to preserve\nmerges when it's rebasing. This addresses a somewhat common boundary case of a\nlocally merged feature branch getting flattened into master, as described here:\n\nhttp://notes.envato.com/developers/rebasing-merge-commits-in-git/\n\nThis current patch adds a new `pull.preserve-merges` boolean config setting, but\nwe could also change the existing `pull.rebase` to be tri-state (so\n`pull.rebase` can be true, false, or preserve-merges), or add a more generic\n`pull.rebaseoptions` that is just a string of flags to pass to rebase.\n\nAny of these would be fine with me--what would be preferred?\n\nThis patch doesn't update the docs, but I wanted to get an initial sanity check\non the preferred config setting before doing that.\n\nThanks!\n\n- Stephen\n\n\nStephen Haberman (1):\n  pull: Allow pull to preserve merges when rebasing.\n\n git-pull.sh     | 11 +++++++++--\n t/t5520-pull.sh | 15 +++++++++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\n-- \n1.8.1.2\n"},{"id":"224834","messageId":"1375983492-32282-2-git-send-email-stephen@exigencecorp.com","threadId":"34642","inReplyTo":"1375983492-32282-1-git-send-email-stephen@exigencecorp.com","subject":"[PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-08T17:38:12Z","receivedAt":"2013-08-08T17:38:12Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"If a user is working on master, and has merged in their feature branch, but now\nhas to \"git pull\" because master moved, with pull.rebase their feature branch\nwill be flattened into master.\n\nThis is because \"git pull\" currently does not know about rebase's preserve\nmerges flag, which would this behavior, and instead replay on the merge commit\nof the feature branch onto the new master, and not the entire feature branch\nitself.\n\nAdd a -p/--preserve-merges, to pass along git rebase if --rebase is in affect.\n\nAlso add a new pull.preserve-merges config setting, to enable this behavior as\nthe default.\n\nSigned-off-by: Stephen Haberman <stephen@exigencecorp.com>\n---\n git-pull.sh     | 11 +++++++++--\n t/t5520-pull.sh | 15 +++++++++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex f0df41c..61d1efb 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -40,7 +40,7 @@ test -f \"$GIT_DIR/MERGE_HEAD\" && die_merge\n \n strategy_args= diffstat= no_commit= squash= no_ff= ff_only=\n log_arg= verbosity= progress= recurse_submodules= verify_signatures=\n-merge_args= edit=\n+merge_args= edit= rebase_args=\n curr_branch=$(git symbolic-ref -q HEAD)\n curr_branch_short=\"${curr_branch#refs/heads/}\"\n rebase=$(git config --bool branch.$curr_branch_short.rebase)\n@@ -48,6 +48,10 @@ if test -z \"$rebase\"\n then\n \trebase=$(git config --bool pull.rebase)\n fi\n+if [ $(git config --bool pull.preserve-merges) = \"true\" ] ;\n+then\n+\trebase_args=--preserve-merges\n+fi\n dry_run=\n while :\n do\n@@ -116,6 +120,9 @@ do\n \t--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)\n \t\trebase=false\n \t\t;;\n+\t-p|--preserve-merges)\n+\t\trebase_args=--preserve-merges\n+\t\t;;\n \t--recurse-submodules)\n \t\trecurse_submodules=--recurse-submodules\n \t\t;;\n@@ -292,7 +299,7 @@ fi\n merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n case \"$rebase\" in\n true)\n-\teval=\"git-rebase $diffstat $strategy_args $merge_args $verbosity\"\n+\teval=\"git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity\"\n \teval=\"$eval --onto $merge_head ${oldremoteref:-$merge_head}\"\n \t;;\n *)\ndiff --git a/t/t5520-pull.sh b/t/t5520-pull.sh\nindex ed4d9c8..2a2ee97 100755\n--- a/t/t5520-pull.sh\n+++ b/t/t5520-pull.sh\n@@ -148,6 +148,21 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '\n \ttest new = $(git show HEAD:file2)\n '\n \n+test_expect_success 'preserve merges' '\n+\tgit reset --hard before-rebase &&\n+\ttest_config pull.rebase true &&\n+\ttest_config pull.preserve-merges true &&\n+\tgit checkout -b keep-merge second^ &&\n+\techo new > file3 &&\n+\tgit add file3 &&\n+\tgit commit -m \"new file3\" &&\n+\tgit checkout to-rebase &&\n+\tgit merge keep-merge &&\n+\tgit pull . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)\n+'\n+\n test_expect_success '--rebase with rebased upstream' '\n \n \tgit remote add -f me . &&\n-- \n1.8.1.2\n"},{"id":"224845","messageId":"20130808140839.56c8343f@sh9","threadId":"34642","inReplyTo":"1375983492-32282-2-git-send-email-stephen@exigencecorp.com","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-08T19:08:39Z","receivedAt":"2013-08-08T19:08:39Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"\n> This is because \"git pull\" currently does not know about rebase's\n> preserve merges flag, which would this behavior, and instead replay\n> on the merge commit of the feature branch onto the new master, and\n> not the entire feature branch itself.\n\nAck, sorry, I was doing this too late last night--should say:\n\nThis is because \"git pull\" currently does not know about rebase's\npreserve merges flag, which would avoid this behavior by replaying the\nmerge commit of the feature branch onto the new master, and not\nreplaying each individual commit in the feature branch.\n\n- Stephen\n"},{"id":"224858","messageId":"alpine.DEB.1.00.1308082314320.24252@s15462909.onlinehome-server.info","threadId":"34642","inReplyTo":"1375983492-32282-2-git-send-email-stephen@exigencecorp.com","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2013-08-08T21:20:10Z","receivedAt":"2013-08-08T21:20:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Stephen,\n\nOn Thu, 8 Aug 2013, Stephen Haberman wrote:\n\n> If a user is working on master, and has merged in their feature branch,\n> but now has to \"git pull\" because master moved, with pull.rebase their\n> feature branch will be flattened into master.\n> \n> This is because \"git pull\" currently does not know about rebase's\n> preserve merges flag, which would this behavior, and instead replay on\n> the merge commit of the feature branch onto the new master, and not the\n> entire feature branch itself.\n> \n> Add a -p/--preserve-merges, to pass along git rebase if --rebase is in affect.\n\nACK!\n\n> Also add a new pull.preserve-merges config setting, to enable this\n> behavior as the default.\n\nThis should probably be added to config.txt and\nDocumentation/git-pull.txt, too, right?\n\nFYI I started to rewrite the complete --preserve-merges support for the\ninteractive rebase some time ago, based on the experience of the merging\nrebases:\n\n\thttps://github.com/msysgit/git/commit/b733454b\n\n(part of the rebase-i-p branch). The idea is to use the 'exec' command of\nthe interactive rebase to do a much better job, and to allow reordering\n(and in particular fixup commits) even when trying to preserve merges.\n\nUnfortunately, the resulting branches look slightly differently now,\nbreaking the (horribly complicated -- my fault!) unit tests, and due to an\nutter lack of time I had to stall that project.\n\nFeel free to play with it if you want!\n\nCiao,\nJohannes\n"},{"id":"224861","messageId":"20130808163539.0b59b20a@sh9","threadId":"34642","inReplyTo":"alpine.DEB.1.00.1308082314320.24252@s15462909.onlinehome-server.info","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-08T21:35:39Z","receivedAt":"2013-08-08T21:35:39Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"Hi Johannes,\n\n> This should probably be added to config.txt and\n> Documentation/git-pull.txt, too, right?\n\nYep, I meant to note that I'd do that after getting an initial\nconfirmation that the pull.preserve-merges was the preferred approach.\n\n(I was being lazy and didn't want to write up docs only to switch to\noverloading pull.rebase or what not.)\n\nBut I'll go ahead and do that.\n\n> \thttps://github.com/msysgit/git/commit/b733454b\n\nInteresting!\n\n> Feel free to play with it if you want!\n\nI'll poke around out of curiosity, but no promises, as, yes, this is a\ntricky bit of functionality that can quickly lead to a lot of lost\nsleep. :-)\n\n- Stephen\n"},{"id":"224865","messageId":"7571F7ED549C4BC68F3DE176FBF81F0F@PhilipOakley","threadId":"34642","inReplyTo":"20130808163539.0b59b20a@sh9","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2013-08-08T21:56:45Z","receivedAt":"2013-08-08T21:56:45Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"Stephen Haberman\" <stephen@exigencecorp.com>\n> Hi Johannes,\n>\n>> This should probably be added to config.txt and\n>> Documentation/git-pull.txt, too, right?\n>\n> Yep, I meant to note that I'd do that after getting an initial\n> confirmation that the pull.preserve-merges was the preferred approach.\n>\n> (I was being lazy and didn't want to write up docs only to switch to\n> overloading pull.rebase or what not.)\n>\n> But I'll go ahead and do that.\n>\n>> https://github.com/msysgit/git/commit/b733454b\n>\n> Interesting!\n>\n>> Feel free to play with it if you want!\n>\n> I'll poke around out of curiosity, but no promises, as, yes, this is a\n> tricky bit of functionality that can quickly lead to a lot of lost\n> sleep. :-)\n>\n> - Stephen\n>\n>\nJohannes also kindly explained his merging-rebase script to me on the \nmsysgit list a few days ago \nhttps://groups.google.com/forum/?hl=en_US?hl%3Den#!topic/msysgit/LiPa2T_K4C4 \nwhich shows how msysgit and git both keep parallel lines of development \nwith fast forwarding and rebasing at the same time.\n\nThe technique should also help those case for keeping \nprivate/independent lines of development that are discussed often.\n\nPhilip\n"},{"id":"224866","messageId":"7vd2pn977v.fsf@alter.siamese.dyndns.org","threadId":"34642","inReplyTo":"20130808163539.0b59b20a@sh9","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-08T21:57:08Z","receivedAt":"2013-08-08T21:57:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephen Haberman <stephen@exigencecorp.com> writes:\n\n> Hi Johannes,\n>\n>> This should probably be added to config.txt and\n>> Documentation/git-pull.txt, too, right?\n>\n> Yep, I meant to note that I'd do that after getting an initial\n> confirmation that the pull.preserve-merges was the preferred approach.\n\nIf you were to go that route, no dashes in the last component of\nconfiguration variable names, please.\n\n> (I was being lazy and didn't want to write up docs only to switch to\n> overloading pull.rebase or what not.)\n\nI think we have a recent update that allows you to say\n\n\t[pull]\n        \trebase = false\n\nto mean \"I want 'git pull' to use merge\".  Currently the other\nchoice is:\n\n\t[pull]\n\t\trebase = true\n\nto say \"I want to run 'git pull --rebase'\".  I do not think it is\nunreasonable to extend it further so that\n\n\t[pull]\n\t\trebase = preserve\n\nis understood.\n"},{"id":"224905","messageId":"alpine.DEB.1.00.1308091618530.24252@s15462909.onlinehome-server.info","threadId":"34642","inReplyTo":"7vd2pn977v.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2013-08-09T14:19:39Z","receivedAt":"2013-08-09T14:19:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 8 Aug 2013, Junio C Hamano wrote:\n\n> Stephen Haberman <stephen@exigencecorp.com> writes:\n> \n> > Hi Johannes,\n> >\n> >> This should probably be added to config.txt and\n> >> Documentation/git-pull.txt, too, right?\n> >\n> > Yep, I meant to note that I'd do that after getting an initial\n> > confirmation that the pull.preserve-merges was the preferred approach.\n> \n> If you were to go that route, no dashes in the last component of\n> configuration variable names, please.\n> \n> > (I was being lazy and didn't want to write up docs only to switch to\n> > overloading pull.rebase or what not.)\n> \n> I think we have a recent update that allows you to say\n> \n> \t[pull]\n>         \trebase = false\n> \n> to mean \"I want 'git pull' to use merge\".  Currently the other\n> choice is:\n> \n> \t[pull]\n> \t\trebase = true\n> \n> to say \"I want to run 'git pull --rebase'\".  I do not think it is\n> unreasonable to extend it further so that\n> \n> \t[pull]\n> \t\trebase = preserve\n> \n> is understood.\n\nWe have a patch in Git for Windows allowing rebase = interactive which I\ndid not have time to send upstream.\n\nCiao,\nJohannes\n"},{"id":"224911","messageId":"20130809102827.3c5d09fa@sh9","threadId":"34642","inReplyTo":"alpine.DEB.1.00.1308091618530.24252@s15462909.onlinehome-server.info","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-09T15:28:27Z","receivedAt":"2013-08-09T15:28:27Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"\n> We have a patch in Git for Windows allowing rebase = interactive\n> which I did not have time to send upstream.\n\nCool, so, would rebase=preserve and rebase=interactive be completely\northogonal?\n\nE.g. do we have to worry about the user wanting to do both, like with\nsomething ugly like rebase=preserve-interactive?\n\nAssuming not, rebase=preserve sounds good to me. I have a patch\nthat does that about ready to submit.\n\n- Stephen\n"}]}