缩进配置仅适用于某些文件 [英] indentation configuration only for some files

查看:76
本文介绍了缩进配置仅适用于某些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用

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

我希望对c ++文件具有这些设置,以便在使用git diff时如果缩进错误,我会收到警告.但是,我也有需要选项卡的Makefile.有没有办法为不同的文件配置不同的空白设置?

I want to have these settings for c++ files, so that I get warnings when there are wrong indentations when I use git diff. However, I have also Makefiles which need tabs. Is there a way to configure different whitespace settings for different files?

推荐答案

您可以使用 gitattributes 调整这些设置.这是我的.gitattributes文件的摘要:

You can use gitattributes to tweak these settings. Here's a snippet of my .gitattributes file:

*.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

要调整空白设置,可以使用类似以下内容的

To adjust your whitespace settings, you could use something like:

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

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

The *.ext can point at paths, contain globs, etc. It's pretty flexible mechanism.

这篇关于缩进配置仅适用于某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆