Converting between tabs and spaces
It is very easy to convert between tabs and spaces automatically when committing and check-outing text files with GIT. GIT allows it with the attributes mechanism:
http://git-scm.com/book/ch7-2.html
http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs
To configure this behavior all you need is:
- Place 'expand' and 'unexpand' commands in your 'PATH' environment variable. For Windows they are part of GnuWin32 CoreUtils package:
- Define needed GIT filter names. These are examples if you want tabs locally and two or four spaces in the repository:
git config --system filter.tabspace2.clean "expand --tabs=2 --initial"
git config --system filter.tabspace2.smudge "unexpand --tabs=2 --first-only"
git config --system filter.tabspace4.clean "expand --tabs=4 --initial"
git config --system filter.tabspace4.smudge "unexpand --tabs=4 --first-only"
- Apply settings to your local repository.
- Create .git/info/attributes file inside your local repository directory and add following line(s) to it:
*.<extension> filter=tabspace2
- Where <extension> is file extension than will be filtered.
- Create .git/info/attributes file inside your local repository directory and add following line(s) to it:
- If you have any changes, commit them and then checkout all files to have filtered version on a disc:
git checkout HEAD -- **
Nemerle
Nemerle
Things may be a little more complicated when you want to do the same with Nemerle source codes, because there is a risk that 'unexpand' command can corrupt files that are using indentation-based syntax. The solution is to use script that expands/unexpands only files with non indentation-based syntax. You can copy tabs_nemerle.sh script to the bin directory of git and configure filters that way:
git config --system filter.tabspace2.clean "tabs_nemerle.sh 2 expand"
git config --system filter.tabspace2.smudge "tabs_nemerle.sh 2 unexpand"