diff to show only the additions in a changed file
You can use --word-diff
to condense the +
and -
lines together with the changes highlighted using red/green text and stop using grep all together.
You can combine this with -U0
to remove all context around the diffs if you really want to condense it down further.
This approch is better than using grep as you don't lose output, you can tell when a line was added or simply changed and you don't completely lose removals while still condensing the output down into something that is easy to read.
The answer to the question regarding egrep is already answered by @Stephen Kitt here
egrep
uses extended regular expressions, so
egrep ^+
matches one or more beginnings of lines (+
is a special character here). To match the “+” character you need to escape it:
egrep ^\+
To see colours, you need to force git
to output them; by default it disables them when piping:
git diff --color
To filter this you need to take the escape codes used for colours into account:
git diff --color ... | egrep '^.[[[:digit:]]+m\+' | less -R