Can git be told to use spaces in ~/.gitconfig?
When I use git config --global <some option> <some value>
, Git will write the relevant entry in my ~/.gitconfig
, indented by one tab . Since my ~/.gitconfig
is version-controlled and I want it to not be a mess, I then have to go in by hand and replace the tab with spaces.
Can Git be told to use spaces automatically when adding entries to ~/.gitconfig
?
(Please note that this is not about the indentation in the code that I'm committing with Git, but rather the indentation in Git's own configuration file.)
This is what worked for me (note that as @rasjani has pointed out in a comment, there is no option to prevent git from inserting a tab in the first place when using git config
.)
Create the filter
Create a filter
to convert tabs to spaces automatically as soon as you do a git add
for a file. This filter is created by
git config --global filter.spacify.clean 'expand --tabs=4 --initial'
The expand
command says that convert each tab character at the beginning of line to 4 space characters
Therefore the definition of the filter includes both what it does and for when it does it (ie for which git operation).
(On OSX, you would need to use gexpand
after installing coreutils by doing a brew install coreutils
)
Of course, you would need to decide the scope ( --system
, --global
or the default --local
) of the above configuration.
Specify the files/path patterns to which the filter will be applied
For instance, for your repository, create a .git/info/attributes
with the following content:
.* filter=spacify
This says that apply the spacify filter to any files that match the pattern .*
before these files are committed to the repository.
Note that the above will only affect new files being added to the repository. If you want this to be done for all existing files, then you could either run expand
manually OR, could get git to do it for us like so:
git config --global filter.spacify.smudge 'expand --tabs=4 --initial'
git checkout HEAD -- **
Using the spacify
filter for smudge
will cause the filter to be applied to files being checked out. After the checkout, you should see a bunch of changes to the dot files which had leading tabs converted to spaces. Re-commit these and from henceforth, the smudge
and clean
duo shall keep your dotfiles tab-free!
Update -- The pull request!
Here is a pull request for your repo : https://github.com/raxod502/radian/pull/156
链接地址: http://www.djcxy.com/p/36676.html上一篇: EXCEPTION:根段不能有矩阵参数