{"thread":{"id":"9707","subject":"Add --rebase option to git-pull?","startedAt":"2007-08-30T12:40:54Z","lastAt":"2007-08-30T20:44:36Z","messageCount":11,"participants":["Tom Clarke","Andreas Ericsson","Johannes Schindelin","Jakub Narebski","Alex Riesen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"51908","messageId":"550f9510708300540u13c77201oe7cbe599c6773364@mail.gmail.com","threadId":"9707","inReplyTo":null,"subject":"Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T12:40:54Z","receivedAt":"2007-08-30T12:40:54Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"Hi,\n\nI'm in the process of setting up a git environment with a number of\nshared branches. To avoid putting unnecessary merges into the trunk,\nwe'd like to normally use rebase when updating private branches. I\nwondered if it would be possible to automatically determine the\ncorrect remote branch to rebase against.\n\nThe most logical place to do this seemed to be in git-pull, so I\nexperimented with adding a '--rebase' option, per the (rough) diff\nbelow.\n\nI'm quite new to git, so is this a good strategy?\n\n-Tom\n\n\ncommit 60b7318c2ebb7ee2bd1afb02f1fc925a29e1b214\nAuthor: Tom Clarke <tom@u2i.com>\nDate:   Thu Aug 30 14:39:34 2007 +0200\n\n    Added --rebase option to pull\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 5e96d1f..233a1d9 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -15,7 +15,7 @@ cd_to_toplevel\n test -z \"$(git ls-files -u)\" ||\n        die \"You are in the middle of a conflicted merge.\"\n\n-strategy_args= no_summary= no_commit= squash=\n+strategy_args= no_summary= no_commit= squash= rebase=false\n while case \"$#,$1\" in 0) break ;; *,-*) ;; *) break ;; esac\n do\n        case \"$1\" in\n@@ -29,6 +29,8 @@ do\n                no_commit=--no-commit ;;\n        --sq|--squ|--squa|--squas|--squash)\n                squash=--squash ;;\n+       --re|--reb|--reba|--rebase)\n+               rebase=true ;;\n        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\\\n                --strateg=*|--strategy=*|\\\n        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)\n@@ -119,5 +121,10 @@ then\n fi\n\n merge_name=$(git fmt-merge-msg <\"$GIT_DIR/FETCH_HEAD\") || exit\n-exec git-merge $no_summary $no_commit $squash $strategy_args \\\n+if test $rebase != \"false\"\n+then\n+    exec git-rebase $strategy_args $merge_head\n+else\n+    exec git-merge $no_summary $no_commit $squash $strategy_args \\\n        \"$merge_name\" HEAD $merge_head\n+fi\n"},{"id":"51910","messageId":"46D6C12A.5090705@op5.se","threadId":"9707","inReplyTo":"550f9510708300540u13c77201oe7cbe599c6773364@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-08-30T13:07:54Z","receivedAt":"2007-08-30T13:07:54Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Tom Clarke wrote:\n> Hi,\n> \n> I'm in the process of setting up a git environment with a number of\n> shared branches. To avoid putting unnecessary merges into the trunk,\n> we'd like to normally use rebase when updating private branches. I\n> wondered if it would be possible to automatically determine the\n> correct remote branch to rebase against.\n> \n> The most logical place to do this seemed to be in git-pull, so I\n> experimented with adding a '--rebase' option, per the (rough) diff\n> below.\n> \n> I'm quite new to git, so is this a good strategy?\n> \n\nIf I read the patch correctly (which I may not, ofcourse), you're\nrebasing the upstream changes to on top of your own work. That's\nnot something you can readily do, since the parentage chain in\ngit is supposed to be immutable, so mutating the one you get from\nan already published source would be a horribly bad idea indeed.\n\nYou need to do it the other way around, so that you rebase your\nlocal changes onto the upstream HEAD prior to pushing.\n\nIf that's what the patch does, then I guess all is fine and dandy,\nalthough I think it'd be better to add the merge-strategy rebase\nor possibly rebase-ours or rebase-theirs, which can be given as\narguments to git-pull.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"51911","messageId":"Pine.LNX.4.64.0708301415150.28586@racer.site","threadId":"9707","inReplyTo":"550f9510708300540u13c77201oe7cbe599c6773364@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-30T13:16:34Z","receivedAt":"2007-08-30T13:16:34Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 30 Aug 2007, Tom Clarke wrote:\n\n> I'm in the process of setting up a git environment with a number of \n> shared branches. To avoid putting unnecessary merges into the trunk, \n> we'd like to normally use rebase when updating private branches. I \n> wondered if it would be possible to automatically determine the correct \n> remote branch to rebase against.\n> \n> The most logical place to do this seemed to be in git-pull, so I \n> experimented with adding a '--rebase' option, per the (rough) diff \n> below.\n\nIn my TODO, there is \"add the 'rebase' strategy\".  It is definitely \nsomething post-1.5.3, so I do not look into it.  But the most logical \nplace for me would be to have a strategy 'rebase'.  IOW a \ngit-merge-rebase.sh.\n\nCiao,\nDscho\n"},{"id":"51912","messageId":"550f9510708300617y69352a67r818000273c25ce11@mail.gmail.com","threadId":"9707","inReplyTo":"46D6C12A.5090705@op5.se","subject":"Re: Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T13:17:46Z","receivedAt":"2007-08-30T13:17:46Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"On 8/30/07, Andreas Ericsson <ae@op5.se> wrote:\n> If I read the patch correctly (which I may not, ofcourse), you're\n> rebasing the upstream changes to on top of your own work. That's\n> not something you can readily do, since the parentage chain in\n> git is supposed to be immutable, so mutating the one you get from\n> an already published source would be a horribly bad idea indeed.\n\nIt's intended to (and appears to) rebase on top of $merge_head, which\nwould typically be something like origin/master or\norigin/topics/my_topic or something. I just noticed I don't need the\n$strategy_args which might be confusing.\n\n> If that's what the patch does, then I guess all is fine and dandy,\n> although I think it'd be better to add the merge-strategy rebase\n> or possibly rebase-ours or rebase-theirs, which can be given as\n> arguments to git-pull.\n\nOk, makes sense.\n\n-Tom\n"},{"id":"51915","messageId":"550f9510708300810y1ca84e8dt4d0bab8fc99deb3c@mail.gmail.com","threadId":"9707","inReplyTo":"Pine.LNX.4.64.0708301415150.28586@racer.site","subject":"Re: Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T15:10:31Z","receivedAt":"2007-08-30T15:10:31Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"On 8/30/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> In my TODO, there is \"add the 'rebase' strategy\".  It is definitely\n> something post-1.5.3, so I do not look into it.  But the most logical\n> place for me would be to have a strategy 'rebase'.  IOW a\n> git-merge-rebase.sh.\n\nThe following is my first naive attempt, is this the kind of thing you\nwere thinking of?\n\nIn addition to running the rebase, I changed the merge script to\nprevent the update-ref as this is (it seems) inappropriate as it\nwasn't really a merge we did.\n\nI'm not sure if any of the other arguments (other than remotes) to the\nmerge script are applicable here.\n\n-Tom\n\ncommit b68df7b3c31953216a03b8f34ffbc6d0c0927ea3\nAuthor: Tom Clarke <tom@u2i.com>\nDate:   Thu Aug 30 17:06:21 2007 +0200\n\n    adding rebase merge strategy\n\ndiff --git a/.gitignore b/.gitignore\nindex 63c918c..dd1aa22 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -74,6 +74,7 @@ git-merge-tree\n git-merge-octopus\n git-merge-one-file\n git-merge-ours\n+git-merge-rebase\n git-merge-recursive\n git-merge-resolve\n git-merge-stupid\ndiff --git a/Makefile b/Makefile\nindex 4eb4637..f6adca2 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -210,7 +210,7 @@ SCRIPT_SH = \\\n        git-sh-setup.sh \\\n        git-am.sh \\\n        git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\n-       git-merge-resolve.sh git-merge-ours.sh \\\n+       git-merge-resolve.sh git-merge-ours.sh git-merge-rebase.sh \\\n        git-lost-found.sh git-quiltimport.sh git-submodule.sh \\\n        git-filter-branch.sh \\\n        git-stash.sh\ndiff --git a/git-merge-rebase.sh b/git-merge-rebase.sh\nnew file mode 100755\nindex 0000000..6140d38\n--- /dev/null\n+++ b/git-merge-rebase.sh\n@@ -0,0 +1,32 @@\n+#!/bin/sh\n+# Resolve two trees with rebase\n+\n+# The first parameters up to -- are merge bases; the rest are heads.\n+bases= head= remotes= sep_seen=\n+for arg\n+do\n+       case \",$sep_seen,$head,$arg,\" in\n+       *,--,)\n+               sep_seen=yes\n+               ;;\n+       ,yes,,*)\n+               head=$arg\n+               ;;\n+       ,yes,*)\n+               remotes=\"$remotes$arg \"\n+               ;;\n+       *)\n+               bases=\"$bases$arg \"\n+               ;;\n+       esac\n+done\n+\n+# Give up if we are given more than two remotes -- not handling octopus.\n+case \"$remotes\" in\n+?*' '?*)\n+       exit 2 ;;\n+esac\n+\n+git update-index --refresh 2>/dev/null\n+\n+git rebase $remotes || exit 2\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 3a01db0..02611f3 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -16,11 +16,12 @@ test -z \"$(git ls-files -u)\" ||\n LF='\n '\n\n-all_strategies='recur recursive octopus resolve stupid ours subtree'\n+all_strategies='recur recursive octopus resolve stupid ours subtree rebase'\n default_twohead_strategies='recursive'\n default_octopus_strategies='octopus'\n no_fast_forward_strategies='subtree ours'\n no_trivial_strategies='recursive recur subtree ours'\n+no_update_ref='rebase'\n use_strategies=\n\n allow_fast_forward=t\n@@ -81,11 +82,18 @@ finish () {\n                        echo \"No merge message -- not updating HEAD\"\n                        ;;\n                *)\n-                       git update-ref -m \"$rlogm\" HEAD \"$1\" \"$head\" || exit 1\n+                       case \" $wt_strategy \" in\n+                       *\" $no_update_ref \"*)\n+                               ;;\n+                       *)\n+                               git update-ref -m \"$rlogm\" HEAD \"$1\"\n\"$head\" || exit 1\n+                               ;;\n+                       esac\n                        ;;\n                esac\n                ;;\n        esac\n+\n        case \"$1\" in\n        '')\n                ;;\n"},{"id":"51917","messageId":"Pine.LNX.4.64.0708301622240.28586@racer.site","threadId":"9707","inReplyTo":"550f9510708300810y1ca84e8dt4d0bab8fc99deb3c@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-30T15:23:00Z","receivedAt":"2007-08-30T15:23:00Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 30 Aug 2007, Tom Clarke wrote:\n\n> On 8/30/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > In my TODO, there is \"add the 'rebase' strategy\".  It is definitely\n> > something post-1.5.3, so I do not look into it.  But the most logical\n> > place for me would be to have a strategy 'rebase'.  IOW a\n> > git-merge-rebase.sh.\n> \n> The following is my first naive attempt, is this the kind of thing you\n> were thinking of?\n\nLooks good to me except for:\n\n> +git update-index --refresh 2>/dev/null\n\nMaybe a test case would be in order, too...\n\nThanks,\nDscho\n"},{"id":"51918","messageId":"550f9510708300826w50b45caesfa88678be1e75115@mail.gmail.com","threadId":"9707","inReplyTo":"Pine.LNX.4.64.0708301622240.28586@racer.site","subject":"Re: Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T15:26:37Z","receivedAt":"2007-08-30T15:26:37Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"On 8/30/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Looks good to me except for:\n>\n> > +git update-index --refresh 2>/dev/null\n>\n> Maybe a test case would be in order, too...\n\nWill do.  Thanks,\n\n-Tom\n"},{"id":"51922","messageId":"fb6sof$6rt$1@sea.gmane.org","threadId":"9707","inReplyTo":"550f9510708300810y1ca84e8dt4d0bab8fc99deb3c@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-08-30T16:54:42Z","receivedAt":"2007-08-30T16:54:42Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Tom Clarke wrote:\n\n> On 8/30/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n\n>> In my TODO, there is \"add the 'rebase' strategy\".  It is definitely\n>> something post-1.5.3, so I do not look into it.  But the most logical\n>> place for me would be to have a strategy 'rebase'.  IOW a\n>> git-merge-rebase.sh.\n> \n> The following is my first naive attempt, is this the kind of thing you\n> were thinking of?\n\nBy the way, such strategy appeared some time ago on git mailing list IIRC as\n'subjugate' (then renamed to 'rebase') merge strategy.\n\nAs with all good ideas (stash, submodules) the idea returns... :-)\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"51935","messageId":"20070830202251.GA15405@steel.home","threadId":"9707","inReplyTo":"550f9510708300810y1ca84e8dt4d0bab8fc99deb3c@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-08-30T20:22:51Z","receivedAt":"2007-08-30T20:22:51Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Tom Clarke, Thu, Aug 30, 2007 17:10:31 +0200:\n> +# Give up if we are given more than two remotes -- not handling octopus.\n> +case \"$remotes\" in\n> +?*' '?*)\n> +       exit 2 ;;\n> +esac\n\nIsn't it \"given two and more remotes\"?\n"},{"id":"51938","messageId":"550f9510708301336v29f2022fodca374881bd82a62@mail.gmail.com","threadId":"9707","inReplyTo":"20070830202251.GA15405@steel.home","subject":"Re: Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T20:36:49Z","receivedAt":"2007-08-30T20:36:49Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"Indeed. Thanks :-).\n\n-Tom\n\nOn 8/30/07, Alex Riesen <raa.lkml@gmail.com> wrote:\n> Tom Clarke, Thu, Aug 30, 2007 17:10:31 +0200:\n> > +# Give up if we are given more than two remotes -- not handling octopus.\n> > +case \"$remotes\" in\n> > +?*' '?*)\n> > +       exit 2 ;;\n> > +esac\n>\n> Isn't it \"given two and more remotes\"?\n>\n>\n"},{"id":"51940","messageId":"550f9510708301344w669e83a8h32ef5bc0547c90d9@mail.gmail.com","threadId":"9707","inReplyTo":"550f9510708301336v29f2022fodca374881bd82a62@mail.gmail.com","subject":"Re: Add --rebase option to git-pull?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-08-30T20:44:36Z","receivedAt":"2007-08-30T20:44:36Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"Actually, it looks I copied the same documentation bug from\ngit-merge-resolve.sh and git merge-stupid.sh\n\n-Tom\n\nOn 8/30/07, Tom Clarke <tom@u2i.com> wrote:\n> Indeed. Thanks :-).\n>\n> -Tom\n>\n> On 8/30/07, Alex Riesen <raa.lkml@gmail.com> wrote:\n> > Tom Clarke, Thu, Aug 30, 2007 17:10:31 +0200:\n> > > +# Give up if we are given more than two remotes -- not handling octopus.\n> > > +case \"$remotes\" in\n> > > +?*' '?*)\n> > > +       exit 2 ;;\n> > > +esac\n> >\n> > Isn't it \"given two and more remotes\"?\n> >\n> >\n>\n"}]}