How do I find out who is responsible for a specific line of code? I know the linenumber and the filename but I would like Mercurial to tell me the author(s) of that specific line of code. Is there a command for that?
7 Answers
On the command-line, you'd want to use hg annotate -u
(-u
can be combined with -n
to get the local revision number, which might come in useful). Check hg help anno
for more options.

- 11,603
- 5
- 41
- 54
-
1I believe that originates with SVN. – Warren P May 24 '13 at 14:11
-
2CVS called it `annotate`. In SVN, the primary for the command is `blame`, although `annotate` and `praise` are available as aliases. – djc May 26 '13 at 19:38
-
6To clarify: this shows who was the last to _edit_ the line, not necessarily who originally created it. – DanMan Feb 13 '15 at 10:38
I was a fan of "svn blame"
, so I've added to my ~/.hgrc
:
[alias]
blame = annotate --user --number
so I can just type "hg blame"
;-)

- 25,229
- 9
- 75
- 117

- 4,850
- 1
- 23
- 31
-
10BTW hg blame is a default command, as far as I can tell. I don't know if it's just recent, but it's there. Caught my attention while I was looking at the helpfile for annotate, which showed aliases "blame" ;) – Tovi7 Mar 13 '12 at 09:34
-
4Tovi7: I added it in February of 2008, so it was first in 1.0. http://hg.intevation.org/mercurial/crew/rev/07f2236c4dee – djc Jun 27 '12 at 15:34
If you are using TortoiseHG
hgtk annotate <filename>
Or by finding the file in the log, rightclicking it and selecting "Annotate file"

- 9,251
- 9
- 48
- 68
I looked for this for ages in Tortoise Workbench; thanks to @artemb and @Steve Pitchers for pointing me in the right direction. Still took me a while to spot it.

- 557
- 7
- 14
-
1To get to that view on the left showing the individual repository files, depress the little button showing in the upper left corner, right where your changed files usually are. Then hover over the numbers by each line and look way at the bottom to see the author in the status bar. – Noumenon Oct 23 '16 at 03:29
In tortoisehg annotate window, there is a new context menu to enable this.
see https://bitbucket.org/tortoisehg/thg/issues/1861/annotate-window-annotate-with-authors

- 3,362
- 2
- 36
- 52
on the command line , you can use either hg blame or hg annotate.
$ hg blame -u -c -l Filename
-u --user list the author (long with -v)
-c --changeset list the changeset
-l --line-number show line number at the first appearance

- 1,767
- 18
- 12
You can also try:
hg blame <file name> | grep -A10 -B10 "<piece of code from the line of interest>"
It will show who made the change to the line, including 10 lines above and 10 lines below the line you are interested in.

- 11
- 2