Print Current Mercurial Revision Hash?

HashMercurialRevision

Hash Problem Overview


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.

Hash Solutions


Solution 1 - Hash

Try:

hg id -i

Example:

$ hg id -i
adc56745e928

Solution 2 - Hash

hg --debug id -i

This will output the long hash, with a plus if there are uncommitted changes.

Solution 3 - Hash

You can use --template with the parent command, I use this to get the long hash:

hg parent --template '{node}'

Solution 4 - Hash

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 - Hash

hg log -l 1 --template '{node|short}\n'

See the docs, paragraphs "The basics of templating" and following.

Solution 6 - Hash

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

Solution 7 - Hash

In case TortoiseHg is used, right-click the revision row in the Workbench and select "Copy hash" (as per documentation).

enter image description here

Solution 8 - Hash

As others have pointed out, don't use log -l.

Use hg log -r . to get detailed information, as opposed to using hg id whose output is limited and it does not support templates. You could also create a little alias like here = log -r . and use hg here. If you only want the hash use hg log -r . --template '{node}\n'.

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
QuestionrentzschView Question on Stackoverflow
Solution 1 - HashRy4an BraseView Answer on Stackoverflow
Solution 2 - HashFrankView Answer on Stackoverflow
Solution 3 - HashshadowspawnView Answer on Stackoverflow
Solution 4 - HashrogView Answer on Stackoverflow
Solution 5 - HashAlex MartelliView Answer on Stackoverflow
Solution 6 - HashShelby Moore IIIView Answer on Stackoverflow
Solution 7 - HashtexnicView Answer on Stackoverflow
Solution 8 - HashGruView Answer on Stackoverflow