I would like to style the bash output for git diff --name-status
so that the files with status D
, M
, and A
are different colors.
To style general git bash I use the color
options in .gitconfig
.
# .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
To style an output for a command like git log
I can use --pretty=format
in an alias like below:
# .gitconfig
[alias]
log = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
However, I have been unsuccessful using --pretty=format
for git diff --name-status
.
The output I would like to style is currently not styled and looks like:
$ git diff <branch> --name-status
M .gitignore
M README.md
A diagnostic.js
D diagnostic.md
Is there a way to style the output git diff --name-status
by status type?
In the diff view there is a file tree showing all of the changes for that pull request. The colour of a particular file indicates the file change type: Green - ADDED (a new file was added) Blue - MODIFIED (an existing file was modified) Brown - COPIED (an existing file was copied to create a new file)
The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.
Sep 13, 2021 at 17:16. 1. Git's original system is just two (well, three) colors: default for unchanged, red for deleted, green for added.
I'm not sure you can colorize the output of --name-status
without entirely reproducing its output with --pretty=format:...
But if you want file names with colors summarizing changes, the --stats
flag can be passed to many commands, including git diff <branch --stat
and git log --stat
.
It shows file names, with a colorized +++--
suffix, e.g.
$ git diff master --stat
lib/thing.go | 5 +++--
lib/thing_test.go | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletion(-)
and the +
s and -
s will colorize according to your git config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With