Mercurial: Easy way to see changes from last commit

Mercurial

Mercurial Problem Overview


In Mercurial, I can see my current (uncommitted) changes by running

$ hg diff

Fine. But after commit, I sometimes want to see this diff again (i.e., the diff of the last changeset). I know I can achieve this by

$ hg log -l 1
changeset:    1234
tag ...

$ hg diff -c 1234

I'm looking for a way to do this in one line.

Mercurial Solutions


Solution 1 - Mercurial

Use hg diff -c tip, or hg tip -p (shorter, but works only for tip).

This will work until you pull something, since tip is an alias for the most recent revision to appear in the repo, either by local commit or pull/push from remote repositories.

Solution 2 - Mercurial

You can use relative revision numbers for the --change option:

hg diff -c -1

See https://stackoverflow.com/a/3547662/239247 for more info.

Solution 3 - Mercurial

An alternative is to use: hg diff --rev -2:-1

This form has the advantage that it can be used with the status command (e.g. hg st --rev -2:-1), and using it makes it easy to remember what to do when one needs to determine differences between other revision pairs (e.g. hg diff --rev 0:tip).

Solution 4 - Mercurial

The answer from Macke is quite helpful, but in my case I didn't want to diff tip.

Thankfully you can also just diff the currently selected comment:

hg diff -c .

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
QuestionclaaszView Question on Stackoverflow
Solution 1 - MercurialMackeView Answer on Stackoverflow
Solution 2 - Mercurialanatoly techtonikView Answer on Stackoverflow
Solution 3 - MercurialpeakView Answer on Stackoverflow
Solution 4 - MercurialHansView Answer on Stackoverflow