How to view revision history for Mercurial file?
Solution 1
hg log file
hg diff -r 10 -r 20 file
Solution 2
The hgk extension gives you hg view file
command that shows a visual history, from which you can diff/vdiff arbitrary pair of revisions.
TortoiseHg gives you thg log file
command that does the same thing but looks better.
Solution 3
For readability
hg diff -r revision1:revision2 file
Where revision1 and revision2 can be a tag, changeset etc.
Solution 4
If you use TortoiseHg: Windows users can use Windows Explorer and view the revision history by right-clicking on the file.
For Linux users, you can do it within TortoiseHg but it took me a while to figure out how. You need to right-click on the desired file and select "File History". However, for some mysterious reason, the file needs to be unaltered. Furthermore, to find the desired file there are two options:
In ### revision set query###
one can type:
file("**<myfile>")
The double ** are necessary to search directories recursively. This gives you immediately an list of all repositories in which the desired file was changed.
Alternatively, next to the ### filter text ###
click first on the question mark sign and select "clean" to see all files in the repository. Then inside the ### filter text ###
box you can narrow down the number of files shown.
Alternatively, Linux users can do it from a terminal as suggested by Geoffrey Zheng above:
thg log file
Related videos on Youtube
![Marcus Leon](https://i.stack.imgur.com/Xk75m.jpg?s=256&g=1)
Marcus Leon
Director Clearing Technology, Intercontinental Exchange. Develop the clearing systems that power ICE/NYSE's derivatives markets.
Updated on February 23, 2020Comments
-
Marcus Leon over 4 years
For a given file in a Mercurial repository, how can you see the revision history?
And how can you diff two revisions of the file?
Ideally doing all this with visual tools (we use ExamDiff to do some other diffs).
I'd say this is basic source control functionality but I can't seem to figure out how to do this with Mercurial.
-
Marcus Leon almost 14 yearsPerfect.. Works with ExamDiff too:
hg examdiff -r 10 -r 20 file
-
milkplus over 12 yearsvery nice! but 'hgtk' is now only a wrapper, please use 'thg' on linux
-
keflavich over 12 yearshgk works for whole revisions, but how do you get it to diff individual files?
-
Despertar over 11 yearsit can also be useful to search a keyword instead of an exact filename, hg log -k keyword
-
temporary_user_name about 9 yearsThis gives me zero output / response; nothing happens.
-
StayOnTarget over 7 yearsMaybe this has changed since 2010, but I can click on a modified file in THG and view the revision history.
-
matteo about 3 yearsWhere do you get the "10" and "20" from?
hg log <file>
shows the long hexadecimal commit IDs, not revision numbers -
zerkms about 3 years@matteo it was 10.5 years ago, those days it was showing it as
id:hash
afair