2017-03-01 12 views
3

我想为git diff --name-status设置bash输出的样式,以便状态为DMA的文件具有不同的颜色。如何通过文件状态添加颜色到'git diff --name-status`的bash输出中?

风格一般的git bash我使用.gitconfig中的color选项。

# .gitconfig 
[color] 
    branch = auto 
    diff = auto 
    status = 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 log一个命令的输出,我可以在一个别名使用--pretty=format象下面这样:

# .gitconfig 
[alias] 
    log = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' 

不过,我已经使用了--pretty=formatgit diff --name-status是不成功的。

我想风格输出目前没有风格,看起来像:

$ git diff <branch> --name-status 
M  .gitignore 
M  README.md 
A  diagnostic.js 
D  diagnostic.md 

有没有一种办法风格深受状态类型的输出git diff --name-status

+1

我从来没有越过'git的差异--name-status'标志上色,但它看起来很像'git的状态 - 具有内置颜色的“短”。这会对你有用吗? –

回答

0

如果你真的真的需要的颜色在你的生活,这可能工作:

# pick your colours 
Red='\033[0;31m'; Colour_Off='\033[0m'; Cyan='\033[0;36m'; 

# find another branch (you could enter <branch>) 
BRANCH=$(git br|grep -v '*'); 

# take the output of git diff and pain the first column red and the reset cyan. 
git diff $BRANCH --name-status|awk "{print \"$Red\" \$1 \"\t\" \"$Cyan\" \$2 \"$Colour_Off\"}" 

您可以创建在bash这个别名或paint.sh

0

我不知道,你可以上色的--name-status输出,而不完全复制其输出与--pretty=format:...

但是如果你想用颜色变化总结文件名,则--stats标志可以传递很多命令,包括git diff <branch --statgit log --stat

它显示文件名,带有彩色+++--后缀,例如,

$ git diff master --stat            
lib/thing.go  | 5 +++-- 
lib/thing_test.go | 23 +++++++++++++++++++++++ 
2 files changed, 28 insertions(+), 2 deletion(-) 

+ S和-旨意根据您的混帐配置

相关问题