gpt4 book ai didi

git - 仅针对某些文件的缩进配置

转载 作者:太空狗 更新时间:2023-10-29 12:51:06 24 4
gpt4 key购买 nike

我要用

git config core.whitespace tab-in-indent,tabwidth=4

我想对 C++ 文件进行这些设置,以便在使用 git diff 时出现错误缩进时收到警告。但是,我也有需要制表符的 Makefile。有没有办法为不同的文件配置不同的空白设置?

最佳答案

您可以使用 gitattributes调整这些设置。这是我的 .gitattributes 文件的片段:

*.c     text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent
*.cpp text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent
*.h text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent
*.hpp text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent
*.py text diff=python whitespace=trailing-space,space-before-tab,tab-in-indent
*.tex text diff=tex whitespace=trailing-space,space-before-tab,tab-in-indent
*.java text diff=java whitespace=trailing-space,space-before-tab,tab-in-indent
*.pl text diff=perl whitespace=trailing-space,space-before-tab,tab-in-indent
*.php text diff=php whitespace=trailing-space,space-before-tab,tab-in-indent
*.rb text diff=ruby whitespace=trailing-space,space-before-tab,tab-in-indent

*.vcproj eol=crlf
*.dsp eol=crlf
*.dsw eol=crlf

*.sh eol=lf

*.jpg binary
*.png binary
*.gif binary
*.tiff binary

要调整空白设置,您可以使用类似的东西:

*.ext   whitespace=tab-in-indent,tabwidth=4

*.ext 可以指向路径、包含 glob 等。这是一种非常灵活的机制。

关于git - 仅针对某些文件的缩进配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13819764/

24 4 0
文章推荐: python - 使用 Selenium 从网页中获取所有可见文本
文章推荐: android -