git - 使用 git 识别修订中所有修改的函数

标签 git function diff history revision

有没有什么好的方法可以用git来识别历史上每个revision中所有修改过的函数?我试过使用 -p 开关,但它的工作方式似乎与 svn 的 show-c-function 参数的工作方式不同。

我的假设是我想使用“git diff HEAD~i HEAD~i-1 -p”来增加 i 的值。我是否遗漏了一些有助于确定 diff 对已修改函数的最佳猜测的参数?

最佳答案

这是一个魔法咒语,用于在 git diff *

中列出函数
git diff |                  \
grep -E '^(@@)' |           \
grep "(" |                  \
sed 's/@@.*@@//' |          \
sed 's/(.*//' |             \
awk -F " " '{print $NF}' |  \
uniq

...它的作用是...

  1. Picks the current diff,
  2. next picks only lines with "hunk-headers" ,
  3. next picks only lines with opening parenthesis (as potentially containing function names),
  4. next ignores the hunk headers,
  5. next ignores the text after the opening parenthesis,
  6. next picks only the word immediately before the opening parenthesis,
  7. and lastly ignores multiple occurrences of the same word in the list.

瞧!您有一个被当前 git diff 修改的函数列表。


* 在运行 bash 的 Ubuntu 16.04 上使用 git version 2.7.4 验证。

关于git - 使用 git 识别修订中所有修改的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5721447/

相关文章:

python - 使用 Rietveld Code Review Tool 进行代码审查

javascript - 立即调用函数表达式

c++ - 当我在 C++ 中将临时 int 分配给 const 引用时会发生什么?

diff - 显示差异在一行中的差异

linux - 我可以使用正则表达式忽略对 diff 的评论吗?

windows - Gitignore 不会忽略 Windows7/8 上 Visual Studio 2015 RC 的 .vs 文件夹

git - 在先前 merge 到开发分支后删除或重新 merge Gitlow 功能分支是否安全?

php - 您可以将函数存储在 PHP 数组中吗?

unix - 在unix中使用sdiff输出侧差的问题

git - 当我执行 git push/git pull 时,是否有可能让 git 自动更新远程服务器上的注释