Git Diff Indent/Pretty Print/Beautify Before Diff

北城以北 提交于 2019-12-18 05:54:14

问题


Is there a way to make Git indent/beautify/pretty print two versions of C++ source files before diffing them?

I don't want Git to show me the myriads of changes introduced after someone auto-formatted the code.

Example usage: I hit git difftool --indent-before-diffing path/to/file and get the changes after both the original version of path/to/file and the modified version of path/to/file have been indented.


回答1:


If you can find an application that does the indenting for you, you could use the method described here for odt files:

Add the following line to your .gitattributes file:

*.odt diff=odt

Now set up the odt diff filter in .git/config:

[diff "odt"]
    binary = true
    textconv = /usr/local/bin/odt-to-txt

So for C++ files it would be something like this:

*.cpp diff=cpp

And in the .git/config:

[diff "cpp"]
    binary = true
    textconv = /path/to/indenter

As pointed out in the comments, GNU Indent can be used for indenting.



来源:https://stackoverflow.com/questions/16357375/git-diff-indent-pretty-print-beautify-before-diff

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