Git - 如何查看方法/函数的更改历史记录? [英] Git - how do I view the change history of a method/function?

查看:52
本文介绍了Git - 如何查看方法/函数的更改历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我找到了关于如何查看文件更改历史的问题,但是这个特定文件的更改历史是巨大的,我真的只对特定方法的更改感兴趣.那么是否可以仅查看该特定方法的更改历史记录?

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?

我知道这需要 git 来分析代码,而且不同语言的分析会有所不同,但方法/函数声明在大多数语言中看起来非常相似,所以我想也许有人已经实现了这个功能.

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.

我目前使用的语言是 Objective-C,我目前使用的 SCM 是 git,但我很想知道此功能是否适用于任何 SCM/语言.

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.

推荐答案

git log 学习了-L参数的一种特殊形式:

-L ::

跟踪由 ","(或函数名正则表达式 )给出的行范围的演变在 中.您不能提供任何路径规范限制器.这目前仅限于从单个修订开始的步行,即您只能给出零个或一个正面的修订参数.您可以多次指定此选项.
...
如果 :" 代替 ,它是一个正则表达式表示从匹配 的第一个 funcname 行到下一个 funcname 行的范围.:" 从前一个 -L 范围的末尾开始搜索,如果有的话,否则从文件的开头开始.^:" 从文件开头搜索.

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,它现在会很高兴地打印该函数的更改历史.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆