Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the rebase command used in hg pull --rebase

Typically, in HG my workflow is to exclusively use:

hg pull --rebase

If I wanted to run this in two commands, how would I do it?

hg pull
hg rebase <probably with some options?>
like image 825
sixtyfootersdude Avatar asked Dec 24 '22 09:12

sixtyfootersdude


1 Answers

What hg pull --rebase does is to indeed first do a hg pull and then hg rebase with default arguments on top of that (you can look at the code in rebase.py in the Mercurial distribution in function pullrebase()), but only if any new revisions were pulled in. If no rebasing is necessary, hg pull --rebase will update to the new branch tip instead. So, hg pull && hg rebase is approximately correct, but doesn't quite capture some corner cases (no new revisions, no rebase necessary).

By default, hg rebase will use the parent of the working directory as the base revision of the rebase and the most recent revision of the current branch (i.e. usually what you just pulled in) as the destination. In short, it's equivalent to hg rebase -b . -d 'last(branch(.))'.

What does "base revision" mean in this context? It means that Mercurial will go and look for the least common ancestor of the base revision and the destination. Then it will rebase everything up to, but not including that least common ancestor on top of the destination. I.e., specifying the base revision allows you to pick pretty much any revision on the branch [1] that you want to rebase and let Mercurial figure out which revisions belong to that branch.

Note that because the rebase is based on the parent of the current working directory, this means that if your current checkout is not what you have been working on, then hg pull --rebase may surprise you by actually trying to rebase a different branch (it will usually fail, because those revisions are generally part of the public phase, but it's something you need to be aware of if you're working with so-called non-publishing repositories and don't use named branches).

[1] Branch in this context refers to an anonymous or topological branch, not a named branch. See hg help glossary for further details.

like image 127
Reimer Behrends Avatar answered Jan 10 '23 05:01

Reimer Behrends