git能自动在空格和制表符之间切换吗?
我在我的python程序中使用缩进标签,但我想与使用空格的人合作(使用git)。
有没有办法使git自动转换空格和制表符(比如4个空格= 1制表符)推/取? (类似于CR / LF转换)
这是完整的解决scheme:
在您的存储库中,添加一个文件.git/info/attributes ,其中包含: 
 *.py filter=tabspace 
的Linux / Unix
现在运行命令:
 git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only' git config --global filter.tabspace.clean 'expand --tabs=4 --initial' 
OS X
先用brew安装coreutils:
 brew install coreutils 
现在运行命令:
 git config --global filter.tabspace.smudge 'gunexpand --tabs=4 --first-only' git config --global filter.tabspace.clean 'gexpand --tabs=4 --initial' 
所有系统
你现在可以看看你的项目的所有文件。 你可以这样做:
 git checkout HEAD -- ** 
和所有的python文件现在将有选项卡,而不是空格。
编辑 :改变强制结帐命令。 当然,你应该先做好你的工作。
是的,一个可能的解决scheme是使用git属性filter驱动程序 (另请参阅GitPro book )来定义一个涂抹/清理机制。

那样:
- 每次你签出你的回购的一些文件,空格可以在标签中转换,
- 但是当您签入(并推送和发布)时,这些相同的文件将仅使用空格进行存储。
 您可以在.git/info/attributes (用于应用于Git tabspace中所有文件的筛选器)中声明此筛选器驱动程序(在此命名为“ tabspace ”),其中包含以下内容: 
 *.py filter=tabspace 
现在运行命令:
 # local config for the current repo git config filter.tabspace.smudge 'script_to_make_tabs' git config filter.tabspace.clean 'script_to_make_spaces' 
参见奥利维尔的答案 ,就是这样一个涂抹/干净的指示的具体工作的例子。
对于使用GitHub(或其他类似服务)的人来说,非常有用的信息
 ~/.gitconfig 
 [filter "tabspace"] smudge = unexpand --tabs=4 --first-only clean = expand --tabs=4 --initial [filter "tabspace2"] smudge = unexpand --tabs=2 --first-only clean = expand --tabs=2 --initial 
 然后我有两个文件: attributes 
 *.js filter=tabspace *.html filter=tabspace *.css filter=tabspace *.json filter=tabspace 
 和attributes2 
 *.js filter=tabspace2 *.html filter=tabspace2 *.css filter=tabspace2 *.json filter=tabspace2 
在个人项目上工作
 mkdir project cd project git init cp ~/path/to/attributes .git/info/ 
 这样,当你最终推动你的工作在github上时,它不会在代码视图中显示出8 space tabs ,这在所有浏览器中都是默认行为。 
贡献于其他项目
 mkdir project cd project git init cp ~/path/to/attributes2 .git/info/attributes git remote add origin git@github.com:some/repo.git git pull origin branch 
 这样你可以使用2 space indented项目的普通标签。 
 当然你也可以编写类似的解决scheme,将4 space to 2 space转换4 space to 2 space ,如果你想为我发布的项目做贡献,而你在开发时倾向于使用2个空间。