Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see git changes after moving code around?

Tags:

git

diff

I am looking at a git diff, most of it is the same code moved from one file to another plus whitespace. How could I see the real differences? I tried git diff -b -C -C to no avail.

like image 719
chx Avatar asked Oct 18 '25 07:10

chx


1 Answers

I came across this via a comment in another SO post, but it seems that since git v2.15 there is the ability to use git diff --color-moved to better differentiate between moved and changed code.

There is a nice example + screenshot showing it's usage on the GitHub git 2.17 release blog post too.

You can find the help/usage for it at https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt

Related options include:

  • --color-moved[=<mode>] (modes: no, default, plain, blocks, zebra, dimmed-zebra)
  • --no-color-moved
  • --color-moved-ws[=<modes>] (modes: no, ignore-space-at-eol, ignore-space-change, ignore-all-space, allow-indentation-change)
  • --no-color-moved-ws
like image 170
Glenn 'devalias' Grant Avatar answered Oct 19 '25 21:10

Glenn 'devalias' Grant



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!