使用 git 识别修订版中所有修改的函数
有没有一个好的方法可以使用git来识别历史记录中每个修订版中所有修改过的功能?我尝试过使用 -p 开关,但它的工作方式似乎与 svn 的 show-c-function 参数的工作方式不同。
我的假设是我想要使用“git diff HEAD~i HEAD~i-1 -p”来增加 i 的值。我是否缺少一些参数,这些参数将有助于识别 diff 对已修改函数的最佳猜测?
Is there a good way to use git to identify all the modified functions in each revision in the history? I've tried using the -p switch, but it doesn't seem to work in the same way that svn's show-c-function parameter works.
My assumption is that I'll want to use "git diff HEAD~i HEAD~i-1 -p" for increasing values of i. Am I missing some parameters that will help identify diff's best guess on the functions that were modified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个神奇的圣歌,用于列出
git diff
* 中的函数......以及它的作用。 ..
瞧!您有一个正在被当前
git diff
修改的函数列表。* 在运行 bash 的 Ubuntu 16.04 上使用
git version 2.7.4
进行验证。Here is a magic chant to list functions within a
git diff
*...and what it does is...
Voila! you have a list of functions being modified by the current
git diff
.* Verified using
git version 2.7.4
on Ubuntu 16.04 running bash.这是我认为你想要的一个快速而肮脏的尝试。它使用
git log
来显示所有修订,使用-p
将差异包含在日志中,使用grep
来仅包含包含提交 ID 和 hunk 标头,并使用 sed 过滤掉行号,只留下对 Git 在 hunk 标头后面写入的函数名称的猜测。Here's a quick and dirty attempt at what I think you're going for. It does a
git log
to show all revisions,-p
to include the diff in the log, agrep
to only include the lines containing the commit ID and the hunk headers, and usessed
to filter out the line numbers, leaving only the guess at the function name that Git writes after the hunk header.您可以使用 git textconv 过滤器列出修订版中所有修改的函数。这个想法是创建一个特定的过滤器,列出所有函数/方法,以及所有函数的主体校验和。这给出了这种过滤后的textconv视图:(
这里
m()
是一个函数签名,12
是其主体的校验和))当
git diff 在修订前后的两个版本上使用此过滤器:
示例:如果修改了函数,则添加 foo
示例:修改 foo 的主体
如何做到这一点?
git config diff.java-ls-methods.textconv /home/path/to/java-ls-methods.groovy
echo "*.java diff=java-ls-methods ”>> .gitattributes
git diff
(与上次提交进行差异)或git diff master
(与另一个分支进行差异).gitattributes
中的行返回到正常的 diff学分:解决方案灵感来自 https://stackoverflow.com/a /16929266
You can list all modified functions in a revision by using git textconv filters. The idea is to create a specific filter that lists all functions/methods, and for all functions, a checksum of the body. This gives this kind of filtered textconv view:
(here
m()
is a function signature,12
is a checksum of its body))When
git diff
uses this filter on the two versions before and after the revision:Example: foo is added
Example: the body of foo is modified
How to do that?
git config diff.java-ls-methods.textconv /home/path/to/java-ls-methods.groovy
echo "*.java diff=java-ls-methods" >> .gitattributes
git diff
(diff against last commit) orgit diff master
(diff against another branch).gitattributes
to go back to a normal diffCredits: solution inspired from https://stackoverflow.com/a/16929266