我在python程序中使用制表符进行缩进,但我希望(使用git)与使用空格的人进行协作。
有没有办法让git在推送/获取时自动转换空格和制表符(比如,4个空格=1个制表符)?(类似于CR/LF转换)
发布于 2013-02-08 03:59:09
对于使用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
项目上的普通选项卡。
当然,你可以编写类似的解决方案来从4 space to 2 space
转换,如果你想为我发布的项目做出贡献,并且你倾向于在开发时使用2个空格,就是这种情况。
https://stackoverflow.com/questions/2316677
复制相似问题