在 Mercurial 中查找一行代码的作者

问题描述 投票:0回答:8

如何找出谁负责特定的代码行?我知道行号和文件名,但我希望 Mercurial 告诉我该特定代码行的作者。有命令吗?

mercurial
8个回答
131
投票

在命令行上,您需要使用

hg annotate -u
-u
可以与
-n
组合来获取本地修订号,这可能会很有用)。检查
hg help anno
了解更多选项。


38
投票

我是

"svn blame"
的粉丝,所以我添加了我的
~/.hgrc

[alias]
blame = annotate --user --number

所以我只需输入

"hg blame"
;-)


16
投票

如果您使用TortoiseHG

hgtk annotate <filename>

或者在日志中找到该文件,右键单击它并选择“注释文件”


10
投票

我在 Tortoise Workbench 中寻找这个很久了;感谢@artemb 和@Steve Pitchers 为我指明了正确的方向。我还是花了一段时间才发现它。

enter image description here


10
投票

在 tortoisehg 注释窗口中,有一个新的上下文菜单可以启用此功能。

参见https://bitbucket.org/tortoisehg/thg/issues/1861/annotate-window-annotate-with-authors


5
投票

在命令行上,您可以使用 hgblame 或 hgannotate。

$ 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
投票

您也可以尝试:

hg blame <file name> | grep -A10 -B10 "<piece of code from the line of interest>"

它将显示谁对该行进行了更改,包括您感兴趣的行上方 10 行和下方 10 行。


0
投票

hg blame <file name> | grep -A10 -B10 "<piece of code from the line of interest>

上面的命令会对整个文件执行blame并返回blame内容。这样,grep 命令就会返回所需的指责行。但是,我的文件大小更大(例如:80,000 行)。为了获取单行的作者详细信息,此命令检索整个 80,000 行的指责内容并 grep 所需的行。这可行吗?

供您参考,在 80,000 行的文件中获取第 20 行的作者姓名大约需要 分钟。是否有任何标志或其他命令来获取给定行的注释内容。

示例: git Blame --line-porcelain -L 10,20 --

© www.soinside.com 2019 - 2024. All rights reserved.