Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the diff specific to a named branch in mercurial

Tags:

mercurial

Assuming I have a named branch foo with two commits a, b:

      a       b       c  
------o-------o-------o------- # default
       \          d         e
        ----------o---------o  # branch foo

I want to see the diff between a and e (a not included). I could of course use the revision id, but that's not very practical. In git, one can just do git diff master..foo. How can I do the same in hg ?

like image 926
David Cournapeau Avatar asked Jan 19 '11 02:01

David Cournapeau


3 Answers

You can do it using revsets.

In your specific example I think you could get a list of of just d and e using:

hg log -r "branch('foo') - branch('default')"

where that - is defined as:

"x - y"
      Changesets in x but not in y.

Getting the diff from a to e could be done as:

hg diff -r "ancestor(default, foo)" -r foo

though there's possibly a shorthand for that I'm not seeing.

like image 132
Ry4an Brase Avatar answered Nov 05 '22 12:11

Ry4an Brase


Another way to do this, useful also for branches that you have already merged to default is:

hg diff -r "max(ancestors(foo) and branch(default)):foo"

Though that can be a pit of a pain, so i'd recommend setting up an alias by adding something like:

[alias]
branchdiff = diff -r "max(ancestors('$1') and branch(default)):'$1'"

To your Mercurial.INI/hgrc which you can then use like this:

hg branchdiff <branch name>

or

hg branchdiff .
like image 41
Richard Avatar answered Nov 05 '22 13:11

Richard


If you want logs from current branch only:

hg log -b .

like image 1
Sid Sarasvati Avatar answered Nov 05 '22 12:11

Sid Sarasvati