When I do a git diff, it shows lines that have been added:
+ this line is added
lines that have been removed:
- this line i
This answer will retain the original red/green colors for readability. I provided a few variations in syntax:
git diff --color | grep --color=never $'^\e\[3[12]m'
git diff --color | grep --color=never $'^\033\[3[12]m'
git diff --color | grep --color=never -P '^\e\[3[12]m'
git diff --color | grep --color=never -P '^\033\[3[12]m'
Explanation:
git diff --color
is needed to prevent git from disabling the color when it is piping.grep --color=never
is to prevent grep removing the original color and highlighting the matched string.\e[31m
) or green (\e[32m
) escape codes.$'...'
(ANSI-C quoting syntax) or -P
(perl syntax) is to let grep
to interpret \e
or \033
as an ESC
character.