Print Current Mercurial Revision Hash?
55,612
Solution 1
Try:
hg id -i
Example:
$ hg id -i
adc56745e928
Solution 2
hg --debug id -i
This will output the long hash, with a plus if there are uncommitted changes.
Solution 3
You can use --template with the parent command, I use this to get the long hash:
hg parent --template '{node}'
Solution 4
Summarising the answers and their responses, it seems that this is the best way to print the unique (not short form) identifier of the current version:
hg log -l 1 --template '{node}\n' -r .
Solution 5
hg log -l 1 --template '{node|short}\n'
See the docs, paragraphs "The basics of templating" and following.
Author by
David Peterson
Updated on August 23, 2022Comments
-
David Peterson almost 2 years
Is there a better way extract the current revision hash in Mercurial than
hg log -l1|grep changeset|cut -d: -f3
?
Part of my webapp deployment script "tags" the uploaded app tarball with its unique revision hash.
-
waterproof over 9 yearsNote that
hg log -l 1
gives you the most recent changeset, not necessarily the one you're currently updated to! The -f flag limits hg log output to ancestors of he current working directory, sohg log -f -l1
is closer to what you want.
-
-
Michael Ekstrand about 13 yearsI wanted almost this, but with the long hash. Aliasing
lid
tolog -l 1 --template '{node}\n'
achieved exactly this - print the full revision ID. -
Eiver over 12 yearsThis prints the most recent pulled changeset. Our working directory could be updated to an older changeset. To print the changeset we are updated to, use "hg id". The only problem is, "hg id" does not support templates nor have an option to print long hash (unless someone knows how to do that).
-
Joseph Lisee about 12 yearsAs Eiver said this does not print the actually revision in your working copy only the latest one in your repository. Because using this solution could introduce tracking errors I have down voted this solution.
-
Joseph Lisee about 12 yearsIn case people miss the solutions below if you want the full hash use:
hg --debug id -i
if you want template support usehg parent --template '{node}'
Do not usehg log -l 1
, its the latest repository changeset, not the current working copy changeset. -
Ry4an Brase about 12 yearsUsing --debug in scripts isn't recommended, that output is less carefully controlled w/r/t backward compatibility. Use the template. If you want to do it w/ log then use
.
dot as the revision. -
Joseph Lisee about 12 yearsThanks Ry4an I had not idea about "-r ." referencing the current working copy revision. That seems like the better move then switching from "log" to "parent".
-
Ry4an Brase about 12 yearsNo prob.
hg help revisions
andhg help revsets
has some crazy powerful shortcuts like that. -
AJP about 10 yearsDitto Joe's downvoting. Also @Eiver use
hg --debug id -i
as is said elsewhere. -
nickd about 9 yearsThat seems to be the default in 3.1.2
-
Shelby Moore III over 8 yearsBut 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 sincehg identify
lacks--template
afaics there is no way to extract just the revision and nothing else since the man page says it prints a summary. -
Shelby Moore III over 8 yearsDownvoting because of Ry4an's comment.
-
Shelby Moore III over 8 yearsThe hg man page says
hg parents
is DEPRECATED, 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. -
Shelby Moore III over 8 yearsNote if there is an uncommitted merge, the
.
(dot) only displays the first parent of two parents of the working group. -
Vincent almost 8 yearsCan someone tell us why hg parents is deprecated and what should we use instead?