Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Mercurial equivalent to git log --first-parent?

git log --first-parent omits all but the first parent of merge commits.

Example:

$ git log --oneline --graph

* 087f5ed Master C
*   36c50a2 Merge branch 'feature'
|\  
| * 98c89df Feature B
| * 89b3a7b Feature A
* | 9a95133 Master B
|/  
* 766c9b0 Master A

$ git log --oneline --graph --first-parent

* 087f5ed Master C
* 36c50a2 Merge branch 'feature'
* 9a95133 Master B
* 766c9b0 Master A

Is there a Mercurial equivalent?

like image 960
Max Nanasy Avatar asked Nov 18 '25 10:11

Max Nanasy


2 Answers

Direct equivalent: hg log -r '_firstancestors(...)'

There is a direct equivalent: the hidden revset _firstancestors follows the first-parent (p1) side of each merge. In Mercurial, like in Git, the first parent is the commit that was checked-out when hg merge [second parent] was called.

hg log -r '_firstancestors(myfeature)'

'hidden' means that it starts with an underscore, and is not listed in the help etc., but can still be used if you know it exists. I don't know why it is hidden.

Examples

This revset alias lists all commits on a feature branch while ignoring all the ancestry whenever master is merged into the branch to bring it up-to-date. (The shop I work prefers merging over rebasing).

[revsetalias]
feature($1) = _firstancestors($1) and not _firstancestors(master)

[alias]
f = log -r "feature($(echo $HG_ARGS| sed 's/^f //'))"

Example usage (uses my own logging template):

$ hg f myfeature
o  423 myfeature default/myfeature -- Esteis -- 2016-07-12 -- 123abc
|  this
o    422 -- Esteis -- 2016-07-12 -- 123def
|\   merge master into myfeature
o ~  421 -- Esteis -- 2016-07-12 -- 456abc
|    that
o  420 -- Esteis -- 2016-07-12 -- 789def
|  and the other
like image 120
Esteis Avatar answered Nov 20 '25 23:11

Esteis


You can use revsets for this:

hg log -r "p1(merge())"

merge() gets all the merge commits and p1() gets the first parent of those commits.

Use hg help revsets to get more information on revsets.

like image 30
Steve Kaye Avatar answered Nov 20 '25 23:11

Steve Kaye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!