首页 > 解决方案 > Git - 获取进行更改的文件的方法/函数名称

问题描述

在 c# 文件中进行更改后如何获取函数/方法名称。

标签: gitfunctionmethodshistory

解决方案


考虑到userdiff.c确实包含 csharp,您只需要添加一个.gitattributes文件(位于您的存储库的根目录),其中包含:

*.cs diff=csharp

然后 agit diff将显示函数名称

有了它.gitattributes,您可以在 diff 之后提取函数名称

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

推荐阅读