Mercurial: Easy way to see changes from last commit
Asked Answered
E

4

66

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.

Epigrammatize answered 17/12, 2012 at 13:52 Comment(0)
A
81

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.

Alexanderalexandr answered 17/12, 2012 at 13:58 Comment(3)
Thanks, this is what I've been looking for. Actually it's -c tip, not -r tip, but the key point is the tip alias.Epigrammatize
@claasz: Glad it helped, and thanks for the tip. I've updated my answer with the right option.Alexanderalexandr
There's a handy shortcut in the form of hg tip -p, but it amounts to the same thing, and the solution given here will work for any revision.Ripsaw
P
16

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

hg diff -c -1

See https://mcmap.net/q/297592/-refer-to-a-mercurial-revision-relative-to-a-named-revision for more info.

Paramorph answered 4/5, 2016 at 11:15 Comment(0)
H
8

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).

Hamstring answered 5/10, 2016 at 6:45 Comment(2)
What is the name of this syntax? I would like to read more about it. Even better, I would like to be able to open a help or man page about this in command line when I need it, since I need it rarely and often forget this syntax, but I don't know what to search for.Boxfish
@Boxfish - you could call it a revset range.Google: hg revision syntaxHamstring
C
5

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 .
Cham answered 24/10, 2019 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.