在 Mercurial 中查找一行代码的作者
如何找出谁负责特定的代码行?我知道行号和文件名,但我希望 Mercurial 告诉我该特定代码行的作者。有这样的命令吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在命令行上,您需要使用
hg annotate -u
(-u
可以与-n
组合来获取本地修订号,这可能有用)。检查hg help anno
了解更多选项。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). Checkhg help anno
for more options.我是
"svnblame"
的粉丝,所以我在我的~/.hgrc
中添加了:这样我就可以输入
"hgblame"
代码>;-)I was a fan of
"svn blame"
, so I've added to my~/.hgrc
:so I can just type
"hg blame"
;-)如果您使用 TortoiseHG
或者在日志中找到该文件,右键单击它并选择“注释文件”
If you are using TortoiseHG
Or by finding the file in the log, rightclicking it and selecting "Annotate file"
我在 Tortoise Workbench 中寻找这个很久了;感谢@artemb 和@Steve Pitchers 为我指明了正确的方向。我还是花了一段时间才发现它。
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.
在 tortoisehg 注释窗口中,有一个新的上下文菜单可以启用此功能。
请参阅https://bitbucket.org/tortoisehg/thg/问题/1861/annotate-window-annotate-with-authors
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
在命令行上,您可以使用 hgblame 或 hgannotate。
on the command line , you can use either hg blame or hg annotate.
您还可以尝试:
它会显示谁对该行进行了更改,包括您感兴趣的行上方 10 行和下方 10 行。
You can also try:
It will show who made the change to the line, including 10 lines above and 10 lines below the line you are interested in.
hg Blame <文件名>; | grep -A10 -B10 "<感兴趣行的一段代码>
上面的命令将为整个文件执行blame并返回blame内容。这样,grep命令就会返回所需的blame行。但是,我的文件大小较大(例如:80,000 行)。要获取单行的作者详细信息,此命令会检索整个 80,000 行的责备内容并 grep 所需的行,这是否可行
?分钟获取 80,000 行文件中第 20 行的作者姓名是否有任何标志或其他命令来获取给定行的带注释内容
。
hg blame <file name> | grep -A10 -B10 "<piece of code from the line of interest>
The above command will execute blame for the entire file and return the blame content. With that, grep command returns the desired blame line. But, my file size is bigger(Eg: 80,000 lines). To get the author details for a single line, this command retrieves blame content for the whole 80,000 lines and greps the desired line. Is this feasible?
For your information, It takes around 5 minutes to get the author name of line 20 in file having 80,000 lines. Is there any flag or other command to get the annotated content of given line.
Example : git blame --line-porcelain -L 10,20 --