我最近看到Windows中的git控制台是有颜色的,例如,绿色表示添加,红色表示删除等等。我怎么给git控制台上色呢?

要安装它,我使用命令:$ sudo apt-get install git-core


当前回答

参考: https://nathanhoad.net/how-to-colours-in-git/

步骤:

~ /开放。Gitconfig用于编辑 六世~ / .gitconfig 粘贴以下代码: (颜色) UI = auto (颜色“分支”) 电流=黄反向 Local =黄色 远程=绿色 (颜色" diff ") Meta =黄色加粗 碎片=洋红色粗体 旧=红色加粗 新=绿色加粗 (颜色“状态”) 新增=黄色 改变=绿色 Untracked =青色 保存文件。

只要改变任何文件在您的本地回购和做

git status

其他回答

添加到你的.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

在你的~/。Gitconfig文件,简单地添加这个:

[color]
  ui = auto

它负责所有的git命令。

参考: https://nathanhoad.net/how-to-colours-in-git/

步骤:

~ /开放。Gitconfig用于编辑 六世~ / .gitconfig 粘贴以下代码: (颜色) UI = auto (颜色“分支”) 电流=黄反向 Local =黄色 远程=绿色 (颜色" diff ") Meta =黄色加粗 碎片=洋红色粗体 旧=红色加粗 新=绿色加粗 (颜色“状态”) 新增=黄色 改变=绿色 Untracked =青色 保存文件。

只要改变任何文件在您的本地回购和做

git status

如果您要求,Git会自动为大部分输出上色。你可以非常具体地说明你想要什么颜色以及如何着色;但是要打开所有默认的终端颜色,请设置颜色。UI为true:

git config --global color.ui true

好吧,如果你对默认设置不满意,你可以使用ANSI转义代码来帮助你设置颜色,如果你想修改一些文本,你可以编写bash来帮助你。如下所示:

埃克斯姆普雷

# .gitconfig

[alias]
    st-color = "!f() { \
        echo -n -e '\\033[38;2;255;0;01m\\033[4m' ;\
        git status -s | grep ' D' | \
        sed -e 's/^ ./DELETE:/' ; \
        echo -n -e '\\033[m' ;\
        \
        echo -n -e '\\033[48;2;128;128;128m' ;\
        echo -n -e '\\033[38;2;0;255;01m' ;\
        git status -s | grep ' [AM]' | \
        sed -e 's/^ ./NEW OR MODIFY:/' ; \
        echo -n -e '\\033[m' ;\
        \
        echo -n -e '\\033[38;2;255;0;255m' ;\
        echo Rename ;\
        git status -s | grep 'R ' | \
        sed -e 's/^..//' ; \
        echo -n -e '\\033[m' ;\
    }; f"

demo

解释

you can write the long script on .gitconfig use the syntax as below: [alias] your-cmd = !f() { \ \ }; f" echo -n -e (see more echo) -n = Do not output a trailing newline. -e Enable interpretation of the following backslash-escaped \\033[38;2;255;0;0m\\033[4m (see more SGR parameters) \\033[38;2;255;0;0m : 38 mean fore color. 255;0;0 = Red | r;g;b \\033[4m : underline grep : The grep command is used to search text. sed -e 's/be_replace_string/new_string/' replace string to new string.