亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

git能在空格和制表符之間自動切換嗎?

git能在空格和制表符之間自動切換嗎?

Git
翻過高山走不出你 2019-05-30 16:57:51
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安裝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文件現在都有制表符而不是空格。

編輯*更改強制簽出命令。當然,你應該先完成你的工作。


查看完整回答
反對 回復 2019-05-30
?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

是的,一個潛在的解決方案是使用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'

看見奧利維爾回答關于這樣一組污點/干凈指令的具體工作示例。


查看完整回答
反對 回復 2019-05-30
?
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/

這樣,當您最終將工作推到GitHub上時,它在代碼視圖中不會顯得很傻。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如果您想要為我發布的項目做出貢獻,并且在開發過程中傾向于使用兩個空格,情況就是這樣。


查看完整回答
反對 回復 2019-05-30
  • 3 回答
  • 0 關注
  • 1313 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號