Script for adding a git filter to locally convert between tabs and spaces, without forcing every repository member to use the same indentation characters.
During checkout, tabs/spaces will be converted into the preferred characters to use locally.
During staging, the characters you use will be converted back to tabs/spaces, producing no extra diffs.
See this answer on StackOverflow and this section of the Pro Git book.
- Windows: none (dependencies are built-in)
- Linux: install
coreutils
(e.g.,sudo apt install coreutils
) - Mac OS: install
coreutils
(e.g.,brew install coreutils
)
-
Open terminal (for Windows, Git Bash or whatever you use).
-
cd
into the root folder of your repository (i.e., the one with.git
folder in it). -
Run
src/install.sh <type> [tab size]
, where<type>
is eithertabs
orspaces
— determines what characters do you want to have locally;[tab size]
is a number of spaces in a tab (optional; defaults to 4).
For example,
src/install.sh tabs 8
orsrc/install.sh spaces 2
-
Open the
.git/info/attributes
file and add/remove file extensions you want to use this script with. Use the*.py
line as an example. -
Stash your changes, if any, and delete all tracked files in the repository folder.
-
Run
git checkout HEAD -- *
-
Enjoy your favorite indentation characters!
- Open terminal (for Windows, Git Bash or whatever you use)
cd
into the root folder of your repository (i.e., the one with.git
folder in it)- Run
src/uninstall.sh