How do I diff one branch with my default branch

Mercurial

Mercurial Problem Overview


I switched to a branch on my local repo and noticed it gave me message showing x files updated. This surprised me as I didn't know there were any differences on that branch. How do I compare that branch with the default branch to see what has changed?

Mercurial Solutions


Solution 1 - Mercurial

Use hg diff -r BRANCH1:BRANCH2, where BRANCH1 and BRANCH2 are the names of the branches. This will show you the differences between the heads of the two branches.

You got the message about "x files updated" because there were files changed on the original branch, not necessarily because there were files changed on the other branch. Mercurial shows you the union of the sets of changed files from both branches.

Solution 2 - Mercurial

To just list the files with differences, add the --stat option:

hg diff --stat -r BRANCH1:BRANCH2

This gives output like this:

mypath/file1.cpp    |    1 -
mypath/file2.cpp    |  143 ++++++++++
mypath/file3.cpp    |   18 +-
3 files changed, 160 insertions(+), 2 deletions(-)

Or to clean up the output a bit, pipe it through sed to remove everything after the pipe symbols:

hg diff --stat -r BRANCH1:BRANCH2 | sed "s/|.*$//g"

This gives you just a list of the changed files and the summary line at the end:

mypath/file1.cpp
mypath/file2.cpp
mypath/file3.cpp
3 files changed, 160 insertions(+), 2 deletions(-)

Solution 3 - Mercurial

To view a diff of branch otherbranch with the current branch:

hg diff -r otherbranch

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjaffaView Question on Stackoverflow
Solution 1 - MercurialNiall C.View Answer on Stackoverflow
Solution 2 - MercurialAnthony.View Answer on Stackoverflow
Solution 3 - MercurialmherzlView Answer on Stackoverflow