git color.ui不适用于Ubuntu 14.10

时间:2015-03-28 19:33:44

标签: git ubuntu

我在ubuntu 14.10上安装了git 2.1.0版。

我创建了一个本地git存储库,现在我想在ubuntu默认终端中用颜色突出显示我的分支。

我做了:

git config --global color.ui true

但它对终端没有影响(我试图重新启动它)。

这是我的〜/ .gitconfig文件的内容:

$ cat ~/.gitconfig 
[alias]
    st = status
        co = checkout
[color]
    ui = true
    branch = auto
    diff = auto
    interactive = auto
    status = auto

当我在我的存储库中时,为什么分支在ubuntu终端中没有着色/突出显示的想法?

我读过这个:

How to color the Git console in Ubuntu?

但这确实提供了任何帮助

enter image description here

我期待这样的事情: enter image description here

2 个答案:

答案 0 :(得分:0)

如果您希望分支名称由git status着色,则显示您必须明确启用此功能。我的猜测是它缺少适用color.ui = auto的默认颜色。

[color "status"]
    branch = green

答案 1 :(得分:0)

如果您想在提示中包含分支名称,请添加到.bashrc

gitbranch() {
    [ -d .git ] && git name-rev --name-only @ | sed -e "s/\\(.*\\)/[\\1]/"
}

PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[\033[00;32m\]$(gitbranch)\[\033[00m\] $ '

由于\[\033[00;32m\]$(gitbranch)\[\033[00m\],分支将显示为绿色。

enter image description here