git能在空格和制表符之间自动切换吗?

git能在空格和制表符之间自动切换吗?

我在python程序中使用选项卡进行缩进,但我希望与使用空格的人协作(使用git)。

在推送/取时,GIT是否可以在空格和制表符(例如,4空格=1制表符)之间自动转换?(类似于CR/LF转换)


翻过高山走不出你
浏览 1181回答 3
3回答

月关宝盒

以下是完整的解决方案:在存储库中,添加一个文件.git/info/attributes其中包括:*.py  filter=tabspaceLinux/Unix现在运行命令:git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only' git config --global filter.tabspace.clean 'expand --tabs=4 --initial'OSX首先用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文件现在都有制表符而不是空格。编辑*更改强制签出命令。当然,你应该先完成你的工作。

慕虎7371278

是的,一个潜在的解决方案是使用Git属性过滤驱动程序(另见Gitpro书),定义污点/清洁机制。这样:每次您签出回购文件时,空格都可以在选项卡中转换,但是,当您签入(并推送和发布)时,这些相同的文件只使用空格存储。您可以声明此筛选器驱动程序(此处命名为“tabspace‘)在.git/info/attributes(对于应用于Gitrepo中所有文件的筛选器),内容如下:*.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'看见奥利维尔氏回答关于这样一组污点/干净指令的具体工作示例。

POPMUISE

对于使用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如果您想要为我发布的项目做出贡献,并且在开发过程中倾向于使用两个空格,情况就是这样。
打开App,查看更多内容
随时随地看视频慕课网APP