When I have a change in a file that consists only of a single very long line, can git diff
output only the part of the line that changed?
I know that git diff --word-diff
will highlight in color only the parts that have changed, but it will still output the full line.
Is there an option to only output the part of the line that has changed? Or perhaps a grep pattern that could match only the colored parts of git diff --word-diff
?
Yes, use git diff --word-diff=porcelain
.
Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/- character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own.
A small change to a long line will look something like...
~
The mouse that the cat that the dog that the
-man
+person
frightened and chased ran away
~
Otherwise you can search for [-
and {+
.