git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/3] rebase: learn --keep-base

From
Denton Liu <liu.denton@gmail.com>
Date
Mar 26, 2019, 21:30 UTC
Message-ID
<20190326213031.GA21504@dev-l>
In-Reply-To
<878sx1bcgr.fsf@evledraar.gmail.com>
Hi Ævar,
On Tue, Mar 26, 2019 at 09:35:48PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 81 quoted lines
> 
> On Tue, Mar 26 2019, Denton Liu wrote:
> 
> > Hi Ævar,
> >
> > On Tue, Mar 26, 2019 at 03:35:34PM +0100, Ævar Arnfjörð Bjarmason wrote:
> >>
> >> On Sat, Mar 23 2019, Denton Liu wrote:
> >>
> >> > This series teaches rebase the --keep-base option.
> >> >
> >> > 'git rebase --keep-base <upstream>' is equivalent to
> >> > 'git rebase --onto <upstream>... <upstream>' or
> >> > 'git rebase --onto $(git merge-base <upstream> HEAD) <upstream>' .
> >> >
> >> > This seems to be a common case that people (including myself!) run into; I was
> >> > able to find these StackOverflow posts about this use case:
> >> >
> >> > * https://stackoverflow.com/questions/53234798/can-i-rebase-on-a-branchs-fork-point-without-explicitly-specifying-the-parent
> >> > * https://stackoverflow.com/questions/41529128/how-do-you-rebase-only-changes-between-two-branches-into-another-branch
> >> > * https://stackoverflow.com/a/4207357
> >>
> >> Like with another series of yours I think this would be best squashed
> >> into one patch.
> >
> > Will do.
> >
> >>
> >> Maybe I've misunderstood this but isn't this like --fork-point except
> >> with just plain "git merge-base" instead of "git merge-base
> >> --fork-point", but then again 2/3 shows multiple base aren't supported,
> >> but merge-base supports that.
> >>
> >
> > --fork-point gets used to determine the _set of_ commits which are to be
> > rebased, whereas --keep-base (and --onto) determine the base where that
> > set of commits will be spliced. As a result, these two options cover
> > orthogonal use-cases.
> 
> Right. After playing with this a bit more though --fork-point is mostly
> there, it it does find the same fork point, as evidenced all your tests
> (that aren't asserting incompatibility with other options) passing with
> this:
> 
>     diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh
>     index 9c2548423b..ab2d50e69a 100755
>     --- a/t/t3416-rebase-onto-threedots.sh
>     +++ b/t/t3416-rebase-onto-threedots.sh
>     @@ -116,7 +116,7 @@ test_expect_success 'rebase --keep-base master from topic' '
>             git checkout topic &&
>             git reset --hard G &&
> 
>     -       git rebase --keep-base master &&
>     +       git rebase $(git merge-base --fork-point master HEAD) &&
>             git rev-parse C >base.expect &&
>             git merge-base master HEAD >base.actual &&
>             test_cmp base.expect base.actual &&
>     @@ -140,7 +140,7 @@ test_expect_success 'rebase -i --keep-base master from topic' '
>             git reset --hard G &&
> 
>             set_fake_editor &&
>     -       EXPECT_COUNT=2 git rebase -i --keep-base master &&
>     +       EXPECT_COUNT=2 git rebase -i $(git merge-base --fork-point master HEAD) &&
>             git rev-parse C >base.expect &&
>             git merge-base master HEAD >base.actual &&
>             test_cmp base.expect base.actual &&
> 
> I've poked at some of this recently in
> https://public-inbox.org/git/20190221214059.9195-3-avarab@gmail.com/ as
> noted in the feedback there (I haven't gotten around to v2 yet) it's
> entirely possible that I haven't understood this at all :)
> 
> But it seems to me that this patch/implementation conflates two
> unrelated things.
> 
> Once is that we use --fork-point to mean that we're going to find the
> divergence point with "merge-base --fork-point". This gets you halfway
> to where you want to be, i.e. AFAICT the --keep-base and --fork-point
> will always find the same commit for "git rebase" and "git rebase
> --keep-base". See the "options.restrict_revision = get_fork_point(...)"
> part of the code.

I don't think this is true. The code that --keep-base uses to find the merge base is get_oid_mb, see the relevant snippet

	if (strstr(options.onto_name, "...")) {
		if (get_oid_mb(options.onto_name, &merge_base) < 0)

whereas the --fork-point code uses get_fork_point, as you mentioned above. As a result, they don't necessarily refer to the same commit in the case where upstream is rewound.

Show 5 quoted lines
> 
> The other, which you want to disable, is that --fork-point *also* says
> "OK, once we've found the divergence point, let's then rebase it on the
> latest upstream. Or in the example above the "master" part of "git
> merge-base --fork-point master HEAD".
Correct, I guess in essence this is what I'm doing.
Show 15 quoted lines
> 
> Shouldn't --keep-base just be implemented in terms of skipping *that*
> part, i.e. we find the fork point using the upstream info, but then
> don't rebase *on* upstream.
> 
> The reason the distinction matters is because with your patch these two
> act differently:
> 
>     git rebase --keep-base
>     git rebase $(git merge-base @{u} HEAD)
> 
> The latter will skip work ("Current branch master is up to date"), but
> --keep-base will always re-rebase things. There's some cases where
> --fork-point does that, which I was trying to address with my linked WIP
> patch above.

I believe this is desired behaviour. Suppose we have this (modified) graph from the git-merge-base docs, where B3 was formerly part of origin/master but it was then rewound:

           ---o---o---B2--o---o---o---B (origin/master)
                   \
                    B3
                     \
                      Derived (local master)
If we run "git rebase --keep-base", we'll get the following graph:
           ---o---o---B2--o---o---o---B (origin/master)
                   \
                    Derived (local master)

which I believe is the desired behaviour (we're abandoning B3 since upstream abandoned it).

I hope I'm understanding you correctly. Please let me know if I've misinterpreted anything you've said or if anything I've said is unclear.

Thanks,
Denton
Show 33 quoted lines
> 
> Whereas the thing you actually want to work is:
> 
>     git rebase -i --keep-base
>     git rebase -i $(git merge-base @{u} HEAD)
> 
> I.e. to have both of those allow you to re-arrange/fixup whatever and
> still rebase on the same divergence point with @{u}, and won't run
> rebase when there's no work to do unless you give it --force-rebase.
> 
> > reason that --onto already disallows multiple bases. If we have multiple
> > bases, how do we determine which one is the "true base" to use? It makes
> > more sense to error out and let the user manually specify it.
> 
> Ah, makes sense.
> 
> >> I'd find something like the "DISCUSSION ON FORK-POINT MODE" in
> >> git-merge-base helpful with examples of what we'd pick in the various
> >> scenarios, and also if whatever commit this picks was something you
> >> could have "git merge-base" spew out, so you could get what rebase would
> >> do here from other tooling (which maybe is possible, but I'm confused by
> >> the "no multiple bases"...).
> >
> > If I'm understanding you correctly then yes, this could be done with
> > other tooling. See the 0/3 for equivalent commands.
> >
> > Perhaps I should update the rebase documentation to mention that
> > --fork-point and --keep-base are orthogonal because it's unclear for
> > you, it's probably unclear for other users as well.
> >
> > Thanks,
> >
> > Denton
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 21 of 123 in “rebase: learn --keep-base”
  1. 0/3 rebase: learn --keep-baseDenton Liu, Mar 23, 2019
  2. 1/3 rebase: teach rebase --keep-baseDenton Liu, Mar 23, 2019
  3. Eric SunshineMar 24, 2019
  4. Junio C HamanoMar 24, 2019
  5. Denton LiuMar 25, 2019
  6. Denton LiuMar 25, 2019
  7. Junio C HamanoApr 1, 2019
  8. Junio C HamanoMar 24, 2019
  9. Denton LiuMar 25, 2019
  10. Johannes SchindelinMar 25, 2019
  11. Denton LiuMar 25, 2019
  12. Johannes SchindelinMar 26, 2019
  13. 2/3 t3416: test rebase --keep-baseDenton Liu, Mar 23, 2019
  14. 3/3 git-rebase.txt: document --keep-base optionDenton Liu, Mar 23, 2019
  15. Junio C HamanoMar 24, 2019
  16. Denton LiuMar 25, 2019
  17. Junio C HamanoApr 1, 2019
  18. Ævar Arnfjörð BjarmasonMar 26, 2019
  19. Denton LiuMar 26, 2019
  20. Ævar Arnfjörð BjarmasonMar 26, 2019
  21. Denton LiuMar 26, 2019
  22. Ævar Arnfjörð BjarmasonMar 27, 2019
  23. rebase: teach rebase --keep-baseDenton Liu, Mar 28, 2019
  24. Ævar Arnfjörð BjarmasonMar 28, 2019
  25. Johannes SchindelinMar 29, 2019
  26. Denton LiuMar 29, 2019
  27. Junio C HamanoApr 1, 2019
  28. 0/4 rebase: teach rebase --keep-baseDenton Liu, Apr 1, 2019
  29. 1/4 t3431: add rebase --fork-point testsDenton Liu, Apr 1, 2019
  30. Denton LiuApr 4, 2019
  31. SZEDER GáborApr 5, 2019
  32. Junio C HamanoApr 8, 2019
  33. Johannes SchindelinApr 5, 2019
  34. Denton LiuApr 5, 2019
  35. Johannes SixtApr 5, 2019
  36. Johannes SchindelinApr 5, 2019
  37. Johannes SchindelinApr 5, 2019
  38. SZEDER GáborApr 5, 2019
  39. 2/4 t3432: test rebase fast-forward behaviorDenton Liu, Apr 1, 2019
  40. 3/4 rebase: fast-forward --onto in more casesDenton Liu, Apr 1, 2019
  41. Junio C HamanoApr 2, 2019
  42. Junio C HamanoApr 2, 2019
  43. Denton LiuApr 2, 2019
  44. 4/4 rebase: teach rebase --keep-baseDenton Liu, Apr 1, 2019
  45. 0/4 rebase: teach rebase --keep-baseDenton Liu, Apr 5, 2019
  46. 1/4 t3431: add rebase --fork-point testsDenton Liu, Apr 5, 2019
  47. 2/4 t3432: test rebase fast-forward behaviorDenton Liu, Apr 5, 2019
  48. 4/4 rebase: teach rebase --keep-baseDenton Liu, Apr 5, 2019
  49. 3/4 rebase: fast-forward --onto in more casesDenton Liu, Apr 5, 2019
  50. 0/5 rebase: teach rebase --keep-baseDenton Liu, Apr 15, 2019
  51. 1/5 t3431: add rebase --fork-point testsDenton Liu, Apr 15, 2019
  52. 2/5 t3432: test rebase fast-forward behaviorDenton Liu, Apr 15, 2019
  53. 3/5 rebase: fast-forward --onto in more casesDenton Liu, Apr 15, 2019
  54. Junio C HamanoApr 16, 2019
  55. Phillip WoodApr 16, 2019
  56. Denton LiuApr 17, 2019
  57. Phillip WoodApr 17, 2019
  58. Denton LiuApr 19, 2019
  59. 4/5 rebase: fast-forward --fork-point in more casesDenton Liu, Apr 15, 2019
  60. 5/5 rebase: teach rebase --keep-baseDenton Liu, Apr 15, 2019
  61. 0/5 rebase: teach rebase --keep-baseDenton Liu, Apr 17, 2019
  62. 1/6 t3431: add rebase --fork-point testsDenton Liu, Apr 17, 2019
  63. 2/6 t3432: test rebase fast-forward behaviorDenton Liu, Apr 17, 2019
  64. 3/6 rebase: refactor can_fast_forward into goto towerDenton Liu, Apr 17, 2019
  65. 4/6 rebase: fast-forward --onto in more casesDenton Liu, Apr 17, 2019
  66. Phillip WoodApr 17, 2019
  67. 5/6 rebase: fast-forward --fork-point in more casesDenton Liu, Apr 17, 2019
  68. 6/6 rebase: teach rebase --keep-baseDenton Liu, Apr 17, 2019
  69. 0/6 rebase: learn --keep-baseDenton Liu, Apr 21, 2019
  70. 1/6 t3431: add rebase --fork-point testsDenton Liu, Apr 21, 2019
  71. Denton LiuApr 23, 2019
  72. 2/6 t3432: test rebase fast-forward behaviorDenton Liu, Apr 21, 2019
  73. 3/6 rebase: refactor can_fast_forward into goto towerDenton Liu, Apr 21, 2019
  74. 4/6 rebase: fast-forward --onto in more casesDenton Liu, Apr 21, 2019
  75. 5/6 rebase: fast-forward --fork-point in more casesDenton Liu, Apr 21, 2019
  76. 6/6 rebase: teach rebase --keep-baseDenton Liu, Apr 21, 2019
  77. 00/13 learn --keep-base & moreÆvar Arnfjörð Bjarmason, May 8, 2019
  78. Junio C HamanoMay 8, 2019
  79. Junio C HamanoJul 19, 2019
  80. Denton LiuJul 19, 2019
  81. 0/9 rebase: learn --keep-base and improvements on fast-forward behaviourDenton Liu, Aug 25, 2019
  82. 1/9 t3431: add rebase --fork-point testsDenton Liu, Aug 25, 2019
  83. 3/9 t3432: distinguish "noop-same" v.s. "work-same" in "same head" testsDenton Liu, Aug 25, 2019
  84. 2/9 t3432: test rebase fast-forward behaviorDenton Liu, Aug 25, 2019
  85. 4/9 t3432: test for --no-ff's interaction with fast-forwardDenton Liu, Aug 25, 2019
  86. 5/9 rebase: refactor can_fast_forward into goto towerDenton Liu, Aug 25, 2019
  87. Pratyush YadavAug 25, 2019
  88. Denton LiuAug 26, 2019
  89. 6/9 rebase: fast-forward --onto in more casesDenton Liu, Aug 25, 2019
  90. 7/9 rebase: fast-forward --fork-point in more casesDenton Liu, Aug 25, 2019
  91. 8/9 rebase tests: test linear branch topologyDenton Liu, Aug 25, 2019
  92. 9/9 rebase: teach rebase --keep-baseDenton Liu, Aug 25, 2019
  93. Philip OakleyAug 25, 2019
  94. Junio C HamanoAug 26, 2019
  95. 0/9 rebase: learn --keep-base and improvements on fast-forward behaviourDenton Liu, Aug 27, 2019
  96. 1/9 t3431: add rebase --fork-point testsDenton Liu, Aug 27, 2019
  97. 2/9 t3432: test rebase fast-forward behaviorDenton Liu, Aug 27, 2019
  98. 3/9 t3432: distinguish "noop-same" v.s. "work-same" in "same head" testsDenton Liu, Aug 27, 2019
  99. 4/9 t3432: test for --no-ff's interaction with fast-forwardDenton Liu, Aug 27, 2019
  100. SZEDER GáborAug 27, 2019
  101. 5/9 rebase: refactor can_fast_forward into goto towerDenton Liu, Aug 27, 2019
  102. 6/9 rebase: fast-forward --onto in more casesDenton Liu, Aug 27, 2019
  103. 7/9 rebase: fast-forward --fork-point in more casesDenton Liu, Aug 27, 2019
  104. 8/9 rebase tests: test linear branch topologyDenton Liu, Aug 27, 2019
  105. 9/9 rebase: teach rebase --keep-baseDenton Liu, Aug 27, 2019
  106. 01/13 t3431: add rebase --fork-point testsÆvar Arnfjörð Bjarmason, May 8, 2019
  107. 02/13 t3432: test rebase fast-forward behaviorÆvar Arnfjörð Bjarmason, May 8, 2019
  108. 03/13 t3432: distinguish "noop-same" v.s. "work-same" in "same head" testsÆvar Arnfjörð Bjarmason, May 8, 2019
  109. 04/13 t3432: test for --no-ff's interaction with fast-forwardÆvar Arnfjörð Bjarmason, May 8, 2019
  110. 05/13 rebase: refactor can_fast_forward into goto towerÆvar Arnfjörð Bjarmason, May 8, 2019
  111. 06/13 rebase: fast-forward --onto in more casesÆvar Arnfjörð Bjarmason, May 8, 2019
  112. 07/13 rebase: fast-forward --fork-point in more casesÆvar Arnfjörð Bjarmason, May 8, 2019
  113. 09/13 rebase tests: test linear branch topologyÆvar Arnfjörð Bjarmason, May 8, 2019
  114. 08/13 rebase: teach rebase --keep-baseÆvar Arnfjörð Bjarmason, May 8, 2019
  115. 10/13 rebase: don't rebase linear topology with --fork-pointÆvar Arnfjörð Bjarmason, May 8, 2019
  116. 11/13 rebase: eliminate side-effects from can_fast_forward()Ævar Arnfjörð Bjarmason, May 8, 2019
  117. Johannes SchindelinMay 17, 2019
  118. 12/13 rebase: add a should_fast_forward() utility functionÆvar Arnfjörð Bjarmason, May 8, 2019
  119. 13/13 WIP: can_fast_forward() support for --preserve-merges and --rebase-mergesÆvar Arnfjörð Bjarmason, May 8, 2019
  120. Johannes SchindelinMay 17, 2019
  121. Ævar Arnfjörð BjarmasonApr 6, 2019
  122. Denton LiuApr 6, 2019
  123. Ævar Arnfjörð BjarmasonApr 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.