git能在空格和制表符之間自動切換嗎?我在python程序中使用選項卡進行縮進,但我希望與使用空格的人協作(使用git)。在推送/取時,GIT是否可以在空格和制表符(例如,4空格=1制表符)之間自動轉換?(類似于CR/LF轉換)
3 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
.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'
OSX
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 -- **
編輯

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
每次您簽出回購文件時,空格都可以在選項卡中轉換, 但是,當您簽入(并推送和發布)時,這些相同的文件只使用空格存儲。
tabspace
.git/info/attributes
*.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
TA貢獻1765條經驗 獲得超5個贊
對于使用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/
8 space tabs
為其他項目作出貢獻
mkdir project cd project git init cp ~/path/to/attributes2 .git/info/attributes git remote add origin [email protected]:some/repo.git git pull origin branch
2 space indented
4 space to 2 space
- 3 回答
- 0 關注
- 1313 瀏覽
添加回答
舉報
0/150
提交
取消