indentation configuration only for some files

前端 未结 3 1866
醉梦人生
醉梦人生 2021-02-08 10:46

I want to use

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

I want to have these settings for c++ files, so that I get warnings when ther

3条回答
  •  Happy的楠姐
    2021-02-08 11:24

    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
    

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

提交回复
热议问题