我最近看到,Windows中的Git控制檯是彩色的,例如,添加綠色,刪除紅色等。如何爲我的Ubuntu Git控制檯添加顏色?如何在Ubuntu中着色Git控制檯?
要安裝它,我使用的命令:$ sudo apt-get install git-core
我最近看到,Windows中的Git控制檯是彩色的,例如,添加綠色,刪除紅色等。如何爲我的Ubuntu Git控制檯添加顏色?如何在Ubuntu中着色Git控制檯?
要安裝它,我使用的命令:$ sudo apt-get install git-core
作爲noted由@VonC,color.ui
默認爲auto
,因爲git 1.8.4。不釋放太快;)
從UNIX & Linux的Stackexchange問題How to colorize output of git?和answer by @Evgeny:
git config --global color.ui auto
的
color.ui
是一元的配置,其中包括所有可用的各種color.*
配置git
命令。這在git help config
中有深入的解釋。
因此,基本上比單獨設置不同的color.*
設置更容易和更有前途。
深入從git config
documentation解釋:
color.ui
:此變量確定變量如color.diff
和color.grep
控制使用每命令家庭顏色的默認值。隨着更多命令學習配置,爲--color
選項設置默認值,其範圍將擴大。如果您希望所有不是用於機器消耗的輸出都使用顏色,請將其設置爲always
,如果您希望此輸出在寫入終端時使用顏色,則需要true
或;如果您希望git命令不使用顏色,則將其設置爲false
或never
除非明確地使用某些其他配置或--color
選項啓用。
例如見http://www.arthurkoziel.com/2008/05/02/git-configuration/
有趣的是
彩色化輸出:
git config --global color.branch auto git config --global color.diff auto git config --global color.interactive auto git config --global color.status auto
我使用舊版本的git並設置'color.ui auto'不適合我,這是。謝謝。 –
在Ubuntu或任何其他平臺(是的,Windows也是!);開始git1.8.4,這是released 2013-08-23,你不會做任何事情:
很多教程教用戶設置「color.ui」到「自動」後的第一件事,你設置「
user.name/email
」來向Git介紹自己。 現在變量默認爲「auto
」。
所以你會看到默認的顏色。
(好吧,甚至Windows,取決於終端:http://stackoverflow.com/a/12133244/6309) – VonC
在2014年使用Ubuntu,安裝了git,仍然必須運行'git config --global color.ui auto' 。我的Mac也是如此,在我的Windows PC上唯一默認爲'auto'的是Git Bash。 – sargas
@sargas當然,你需要安裝[從PPA](https://launchpad.net/~git-core/+archive/ppa):https://launchpad.net/~git-core/+archive/ ppa(用於Ubuntu)或http://git-scm.com/download/mac(用於Mac) – VonC
如果您要求,Git會自動爲其大部分輸出着色。你可以非常具體地瞭解你想要的顏色和方式;但打開所有的默認終端着色,設置color.ui爲true:
git config --global color.ui true
另一種方法是編輯.gitconfig
(創建一個如果不存在),例如:
vim ~/.gitconfig
和然後加入:
[color]
diff = auto
status = auto
branch = auto
as @ chuntao-lu提到'[color] ui = auto'就夠了。 –
在你~/.gitconfig
文件,只需補充一點:
[color]
ui = auto
它會照顧你所有的git命令。
添加到您的.gitconfig文件下面的代碼:
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
GIT默認,但一些系統上採用彩色輸出等爲CentOS的它未啓用。你可以像這樣啓用它
git config --global color.ui true
git config --global color.ui false
git config --global color.ui auto
你可以從這裏選擇你需要的命令。
這裏- 全局是可選的,可以對系統中的每個存儲庫應用操作。如果你想爲當前倉庫應用着色,那麼你可以做這樣的事情 -
git config color.ui true
開始git1.8.4,你應該看到默認的顏色。請參閱[我的答案](http://stackoverflow.com/a/17278947/6309)。 – VonC
在Ubuntu 14.04上,@VonC git 1.9.1沒有發生。必須自己設置JoelPurra的答案。 – Izkata
@Izkata奇怪,我會稍後再測試一下,但是git 2.1+怎麼樣? (正如我在下面評論在http://stackoverflow.com/questions/10998792/how-to-color-the-git-console-in-ubuntu?noredirect=1#comment33988696_17278947) – VonC