In a mercurial repo I can run hg up {revision}
to change the revision of my working directory, but what command can I run to discover what revision I'm looking at?
6 Answers
This command:
hg parent

- 249,484
- 69
- 436
- 539
-
@pyfunc: i've wasted about minute with terrible captchas, otherwise I could be first :-) – zerkms Dec 02 '10 at 00:47
-
No issues. The best part is I was doing some thing on my mercurial repo and I muddled the two tasks. :) – pyfunc Dec 02 '10 at 00:53
-
1The hg man page says `hg parents` is [DEPRECATED](https://www.selenic.com/mercurial/hg.1.html#parents), although perhaps that might not have been the case when you wrote this answer. If there is an uncommitted merge, there are [two parent revisions](https://www.mercurial-scm.org/wiki/UnderstandingMercurial#line-157). – Shelby Moore III Nov 26 '15 at 16:12
-
1Why is this command called "parent"? It shows information about the current commit, not the current commit's parent. – Jamie Jul 19 '16 at 17:10
-
2@Jamie naming is hard :-D – zerkms Jul 19 '16 at 20:59
In addition to hg parents
, you can use hg summary
to get the most important summary information about your current state. It looks like this:
% hg summary
parent: 13051:120eccaaa522 tip
encoding: fix typo in variable name
branch: default
commit: 2 unknown (clean)
update: (current)
mq: 20 unapplied
and tells me at a glance that I'm at revision 13051, that I'm on the default branch with a clean working copy (though there are 2 untracked files). This is the tip revision in my repository, so an update wont do anything. Finally, I have 20 unapplied MQ patches.

- 72,968
- 25
- 171
- 229
-
-
Nah, I lose the overview with qqueue. Instead I just group the patches in small batches: 4 patches for feature X, 5 patches for feature Y, etc. If I want to work on feature X, then I move the relevant patches up front in the queue using the TortoiseHg log viewer. – Martin Geisler Dec 09 '10 at 11:46
-
But it is not the most specific answer to the question, because since `hg summary` lacks `--template` there is no way to extract just the revision and nothing else. – Shelby Moore III Nov 26 '15 at 13:34
hg identify
(or hg id
for short) will print the (shortened 12-character identifier of) the parent hashes, and a +
if there are any uncommitted modifications in your working copy.
To get the full hashes, you can use hg identify --debug
instead.

- 66,094
- 13
- 157
- 251
-
1Just as a note, by default, `hg parent` shows more info than `hg id`. – gbmhunter Apr 16 '14 at 23:54
-
But it is not the most specific answer to the question, because afaik `hg id -i` prints only the short (12 characters) form of the global hash id and since `hg identify` lacks `--template` afaics there is no way to extract just the revision and nothing else since the [man page says](https://www.selenic.com/mercurial/hg.1.html#identify) it prints a summary. Also don't you need `hg id -n` and/or `hg id -i`? – Shelby Moore III Nov 26 '15 at 14:14
-
2@ShelbyMooreIII 12 hex characters is 6 bytes, or 48 bits, so there are 2^48 possible short identifiers. According to the birthday paradox, about 1.2 * sqrt(2^48) = roughly 2 million commits are then needed to get a 50% probability of a collision. The short identifier will almost always be fine. – Wim Coenen Nov 26 '15 at 19:04
-
1[Correct math](http://preshing.com/20110504/hash-collision-probabilities/) says roughly 15 million for 50% collision probability. But who would use a system with a 50% probability of failure. Take a more reasonable safety margin of 1-in-million chance of failure, then the number of commits drops to less than 25,000. The acceptable level of probability will depend on the application. For example, is that 12 digit hexadecimal being recorded in changeset comments. Note in DVCS it is not just our local commits that matter but potentially everyone's experiments. Avoid “wtf” surprise. – Shelby Moore III Nov 26 '15 at 20:02
-
@ShelbyMooreIII fine, I've amended my answer with a way to get the full hashes from hg identify. – Wim Coenen Nov 27 '15 at 13:33
-
See Ry4an's [comment](http://stackoverflow.com/questions/2485651/print-current-mercurial-revision-hash#comment14377031_2485923) for why `--debug` is considered bad form for scripting. The reason I pedantically harped on the ability to use `--template` in my answer is interoperability with scripting. It seems you also didn't fully parse my point about the man page for `hg identity` implying it can print a "summary" (but didn't precisely define what summary) and thus the defined output is not necessarily stable for scripting over time. No bad vibes intended. Cheers. – Shelby Moore III Nov 27 '15 at 14:01
-
This combined with `hg show` to show latest commit: ``hg show `hg id -i` `` – KFL Dec 04 '18 at 17:35
Another option is to enable the graphlog extension, then run hg glog
. You'll see output like this (bear in mind I use a template to change the output):
o changeset: 200:c8c281cf0a6d
|\ branch: craig-aspinall
| | tag: tip
| | parent: 199:1a692f3b9134
| | parent: 187:2d0e0ed9d31c
| | user: Craig Aspinall
| | date: Tue Nov 23 21:36:30 2010 +1000
| | summary: Merged latest changes
| |
| o changeset: 199:1a692f3b9134
| | branch: craig-aspinall
| | parent: 123:1dc90c9b7ede
| | user: Craig Aspinall
| | date: Tue Nov 23 21:35:22 2010 +1000
| | summary: Final solutions to L04
| |
| | @ changeset: 198:78b488c2607d <==== This is where I am currently.
| | |\ branch: OJ
| | | | parent: 119:70ec3d9e4d3a
| | | | parent: 197:44bac809d37d
| | | | user: OJ Reeves
| | | | date: Tue Nov 23 20:19:07 2010 +1000
| | | | summary: Merged with the mainline
| | | |
| | | o changeset: 197:44bac809d37d
| | | | user: Tony Morris
| | | | date: Tue Nov 23 18:40:03 2010 +1000
| | | | summary: Started parallel anagrams
| | | |
| | | o changeset: 196:92241b51970b
| | | | user: Tony Morris
| | | | date: Tue Nov 23 17:52:32 2010 +1000
| | | | summary: Started parallel anagrams
| | | |
The node/revision with the @
symbol is where you are.

- 28,944
- 5
- 56
- 71
-
Maybe this output is faked, but I'm not sure this answer should contain people's names. – Clonkex Mar 08 '22 at 04:01
The most specific non-DEPRECATED command which due to the presence of --template
can print only revision information if that conciseness is required (as implied by the question):
hg log -l 1 -b . -T '{rev}:{node|short}\n'
Or:
hg log -l 1 -b . -T '{rev}\n'
Or:
hg log -l 1 -r . -T '{rev}\n'
Or for unique long form of hash:
hg log -l 1 -r . -T '{node}\n'
The -b .
or branch(.)
(dot for branch name) means the current working directory branch and -r .
means the current working directory revision, which is documented in hg help revsets
and hg help revisions
.
Note if there is an uncommitted merge, the .
(dot) only displays the first parent of two parents of the working group.

- 1
- 1

- 6,063
- 1
- 33
- 36