Is there something similar to diff --show-c-function in git-diff?

烂漫一生 提交于 2019-12-10 13:18:02

问题


I've been working on a file in my git repository. If I have a copy of the original git version of the file, I can run diff --show-c-function to get a comparison of the 2, files, where (in theory) it shows the whole of any function which has been changed. This is really useful for working out what I did specifically to a file, in working out the comment I'd need.

However in git-diff, this option is missing. Is there some way to make this work (or am I stuck having to get 2 copies of the file before I can commit, where the git-diff response is slightly complicated)?


回答1:


git help diff shows this option:

-W, --function-context
        Show whole surrounding functions of changes.

So, it looks like git diff -W should do what you want.




回答2:


Note that GNU diff's --show-c-function option doesn't show you the text of the C function the change (hunk) is in, it just shows you the function name in the hunk heading (after the @@ .. @@ text).

git does the same thing in its diffs by default (at least as of 1.9), and it also makes it configurable via the core.attributesfile file.



来源:https://stackoverflow.com/questions/16525659/is-there-something-similar-to-diff-show-c-function-in-git-diff

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!