Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit diff show line update in only one line

Tags:

git

diff

show

I know that by using the commands

git show / git diff

I can get the line changes, nevertheless they print line modifications as a + line preceded by a - line. I recall finding somewhere an option to only show the modification in one line, with the changes printed in red (old) and green (new).

Note:

To clarify it a little, for example, by using the command git show <commitId> I will be getting:

-     <property>horses</property>
+     <property>humans</property>

The minus line appears in red and the plus line in green. What I want to accomplish is to have the change in only one line, still I do not remember how the prefix appeared, but I believe it was something like:

+     <property>[horses]humans<property>

Where the whole line appears green and the word horses appears red. I know this can be done because I did it in the past with some random command I got from a page that sadly cannot remember.

like image 456
will824 Avatar asked Aug 12 '26 08:08

will824


1 Answers

If

$ git diff --word-diff=color

, as Peter mentioned, is not the output you want, you could try:

$ git diff --word-diff=plain

This will print some additional brackets {} and signs + -, around the differences. But it also will show the same colorful output as word-diff=color will do.

To show differences per word in the 7th last commit, use:

$ git diff HEAD~7 --word-diff=plain



$ git diff

»

-                       // check for twice same password
+                       // check is password twice

$ git diff --word-diff=color

»

                        // check for twice sameis password twice

$ git diff --word-diff=plain

»

                        // check [-for twice same-]{+is+} password {+twice+}
like image 183
Sebastian Blei Avatar answered Aug 15 '26 00:08

Sebastian Blei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!