Git - 如何查看方法/函数的更改历史记录? [英] Git - how do I view the change history of a method/function?
问题描述
我知道这需要git来分析代码,并且分析结果会因不同而有所不同语言,但方法/函数声明在大多数语言中看起来非常相似,所以我想也许有人已经实现了这个功能。
我目前使用的语言是Objective- C和我目前使用的SCM是git,但我很想知道这个功能是否适用于任何SCM /语言。
>最近版本的 git log
已学习 -L
参数的特殊形式:
-L: < funcname>:< file>
跟踪由
< start>,<< (或函数名正则表达式
< funcname>
)的结尾><文件>
。您不可以提供任何路径限制器。这目前仅限于从单个修订开始,也就是说,您可能只给出零个或一个正面修订参数。您可以多次指定此选项。
...
如果:< funcname>
< start>
和< end>
的位置,它是一个正则表达式,表示从第一个与< funcname>
匹配的funcname行,直到下一个funcname行。:< funcname>
从前一个-L
范围的末尾搜索(如果有的话),否则从文件开始。^:< funcname>
从文件开始的搜索。
换句话说:如果你要求Git git log -L:myfunction:path / to / myfile.c ,它现在会很高兴地打印出该函数的变化历史记录。
So I found the question about how to view the change history of a file, but the change history of this particular file is huge and I'm really only interested in the changes of a particular method. So would it be possible to see the change history for just that particular method?
I know this would require git to analyze the code and that the analysis would be different for different languages, but method/function declarations look very similar in most languages, so I thought maybe someone has implemented this feature.
The language I'm currently working with is Objective-C and the SCM I'm currently using is git, but I would be interested to know if this feature exists for any SCM/language.
Recent versions of git log
learned a special form of the -L
parameter:
-L :<funcname>:<file>
Trace the evolution of the line range given by
"<start>,<end>"
(or the function name regex<funcname>
) within the<file>
. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments. You can specify this option more than once.
...
If":<funcname>"
is given in place of<start>
and<end>
, it is a regular expression that denotes the range from the first funcname line that matches<funcname>
, up to the next funcname line.":<funcname>"
searches from the end of the previous-L
range, if any, otherwise from the start of file."^:<funcname>"
searches from the start of file.
In other words: if you ask Git to git log -L :myfunction:path/to/myfile.c
, it will now happily print the change history of that function.
这篇关于Git - 如何查看方法/函数的更改历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!