c++ - Git Diff Indent/Pretty Print/Beautify Before Diff

标签 c++ git indentation pretty-print git-diff

有没有办法让 Git indent/beautify/pretty 在 diff 之前打印两个版本的 C++ 源文件?

我不希望 Git 向我显示在有人自动格式化代码后引入的无数更改。

示例用法:我点击 git difftool --indent-before-diffing path/to/file 并在 path/to/file 的原始版本之后获取更改> 和 path/to/file 的修改版本已经缩进。

最佳答案

如果您能找到为您缩进的应用程序,您可以使用描述的方法 here对于 odt 文件:

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

所以对于 C++ 文件,它将是这样的:

*.cpp diff=cpp

在 .git/config 中:

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

正如评论中指出的那样,GNU Indent可用于缩进。

关于c++ - Git Diff Indent/Pretty Print/Beautify Before Diff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16357375/

相关文章:

c++ - Multisample framebuffer 仅与 renderbuffer 不完整

c++ - 有一个返回 int 的函数,如何使用 boost 在单独的线程中运行它?

python - 使用 NRF24L01 将 Arduino 浮点值转换为 Python

linux - 如何通过终端自动创建文件和文件夹?

indentation - TypeScript 中的 Allman 式大括号

PHP 正确缩进?

c++ - 备用函数语法/函数原型(prototype)?

macos - Git 命令在 Mac 终端 : "dyld: Symbol not found: ___strlcpy_chk" error 中不起作用

git - 如何在 Jenkins 构建之前 merge 到一个临时分支

php - 整理 PHP 和 HTML 代码?