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

Re: rebase -i: learn to rebase root commit

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 30, 2008, 12:23 UTC
Message-ID
<200812301323.30550.trast@student.ethz.ch>
In-Reply-To
<200812291621.35732.bss@iguanasuicide.net>
Boyd Stephen Smith Jr. wrote:
Show 5 quoted lines
> Here's the interpretation that *I* come up with for -p --root used together:
> The commit with no parents (OLD_ROOT) is rebased as if -p were not given, call 
> the resulting commit NEW_ROOT.  Then, the rebase continues as if "--onto 
> NEW_ROOT OLD_ROOT <branch>" was specified instead of "--onto=NEW_ROOT^ --root 
> <branch>".

I like this logic, but it feels inconsistent as soon as there are several root commits. (This may be somewhat academic, since any repo with several roots should also be able to cope with a merge...)

Some digging into the -p code shows that it knows which commits were rewritten, and which were untouched. It rewrites such that _all_ commits in $(git merge-base --all $branch $upstream) are rewritten to look like $onto instead, i.e., all their occurrences in parent lists of commits are rewritten to $onto. All other commits are only rewritten if they have a parent that was rewritten.

So I think one sane way is to define a virtual parent 'root', and think of parentless commits as having the (sole) parent 'root'. Then we can rewrite such that 'root' becomes $onto, i.e., all occurrences of 'root' in parent lists become $onto, consistent with the normal operation. (For the other commits, the same rule as above is applied.)

Of course this just boils down to saying that _all_ root commits reachable from $branch are rewritten to have $onto as their parent. Subsequently, all other commits will also be rewritten because they all must have at least one rewritten parent.

> Basically, --root only changes how the first commit is handled, which I think 
> is consistent with other uses of --root.  It's also similar to cherry-picking 
> the first commit, follwed by a non-root rebase, which I think is also 
> consistent with the intention of --root.

I believe this remark still holds if there is only a single root commit on $branch.

I will reroll with an updated 2/3 shortly.
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Boyd Stephen Smith Jr.Next: Thomas Rast
Message 7 of 27 in “rebase --root”
  1. 0/3 rebase --rootThomas Rast, Dec 29, 2008
  2. rebase: learn to rebase root commitThomas Rast, Dec 29, 2008
  3. rebase -i: learn to rebase root commitThomas Rast, Dec 29, 2008
  4. rebase: update documentation for --rootThomas Rast, Dec 29, 2008
  5. Thomas RastDec 29, 2008
  6. Boyd Stephen Smith Jr.Dec 29, 2008
  7. Thomas RastDec 30, 2008
  8. 1/3 rebase: learn to rebase root commitThomas Rast, Dec 30, 2008
  9. 2/3 rebase -i: learn to rebase root commitThomas Rast, Dec 30, 2008
  10. 3/3 rebase: update documentation for --rootThomas Rast, Dec 30, 2008
  11. Junio C HamanoJan 1, 2009
  12. Johannes SchindelinJan 2, 2009
  13. Thomas RastJan 2, 2009
  14. 1/4 rebase -i: execute hook only after argument checkingThomas Rast, Jan 2, 2009
  15. 2/4 rebase: learn to rebase root commitThomas Rast, Jan 2, 2009
  16. 3/4 rebase -i: learn to rebase root commitThomas Rast, Jan 2, 2009
  17. 4/4 rebase: update documentation for --rootThomas Rast, Jan 2, 2009
  18. 3/4 rebase -i: learn to rebase root commitThomas Rast, Jan 2, 2009
  19. 2/4 rebase: learn to rebase root commitThomas Rast, Jan 2, 2009
  20. Junio C HamanoJan 2, 2009
  21. rebase: learn to rebase root commitThomas Rast, Jan 2, 2009
  22. rebase: learn to rebase root commitThomas Rast, Jan 5, 2009
  23. Junio C HamanoJan 6, 2009
  24. Junio C HamanoJan 2, 2009
  25. Thomas RastJan 2, 2009
  26. Junio C HamanoJan 2, 2009
  27. Junio C HamanoDec 30, 2008

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.