所以我发现了关于如何查看文件更改历史的问题,但是这个特定文件的更改历史很大,我真的只对特定方法的更改感兴趣。那么是否可以仅查看该特定方法的更改历史记录?
我知道这需要 git 来分析代码,并且不同语言的分析会有所不同,但是方法/函数声明在大多数语言中看起来非常相似,所以我想也许有人已经实现了这个功能。
我目前使用的语言是 Objective-C,我目前使用的 SCM 是 git,但我很想知道这个功能是否适用于任何 SCM/语言。
最佳答案
git log
的最新版本学习了 -L
的特殊形式参数:
-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.
换句话说:如果你向 Git 询问 git log -L :myfunction:path/to/myfile.c
,它现在会愉快地打印该函数的更改历史记录。
关于objective-c - Git - 如何查看方法/函数的更改历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4781405/