gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:31:05 27 4
gpt4 key购买 nike

有没有什么好的方法可以用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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com