Mercurial: diffs in a particular changeset?

Mercurial

Mercurial Problem Overview


This is almost exactly a duplicate of Examining a single changeset in Mercurial, and without doubt a duplicate of another question I can't find on SO through Google alone.

I'm looking back through a Mercurial repo, and I want to see what exactly changed between two revisions (let's say 2580 and 2581):

hg log -v -r 2581 

gives me all the files that changed.

How can I also see the diffs of these files?

Thanks.

Mercurial Solutions


Solution 1 - Mercurial

Revision 2580 isn't necessasrily the parent revision of 2581. It's easy to check if it is, of course, but easier yet is to just do:

hg log -p -r 2581

That compares 2581 to its (first) parent revision no matter what it is, and most clearly encompasses the answer to the question "what the hell did 2581 do?"

Solution 2 - Mercurial

Try hg diff -r 2580 -r 2581.

Solution 3 - Mercurial

hg diff -r 2580 -r 2581

This is a wrong example. The revision 2580 can be in another branch and you get diff between two branches.

Use

hg log -p -r 2581

or hg diff -c 2581

The difference between them in the first lines. Hg log also show information about changeset (parent, author, date, ...)

I prefer second variant hg diff -c ... because it can store to patch files.

hg diff -c 2581 > revision_2581.patch

Solution 4 - Mercurial

Another solution is to use revset notation which IMO is a better solution as you can use it in more places consistently (ie you don't need to know about diff -c and log -p ).

hg diff -r 'last(ancestors(2581),2)'

Yes that is rather verbose compared to -c (for diff) and -p (for log).

However mercurial allows you to create revset aliases

In your .hgrc:

[revsetalias]

next(s) = descendants(s, 1)
prev(s) = last(ancestors(s),2)

Now you can do

hg diff -r 'prev(2581)'
hg log -r 'prev(2581)'

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
QuestionAP257View Question on Stackoverflow
Solution 1 - MercurialRy4an BraseView Answer on Stackoverflow
Solution 2 - MercurialvissiView Answer on Stackoverflow
Solution 3 - MercurialthekostyaView Answer on Stackoverflow
Solution 4 - MercurialAdam GentView Answer on Stackoverflow