Search code examples
diffgit-diff

How can I make `git diff` as fine-grained as StackExchange diff?


Is there a diff tool which can highlight single character edits as such, and not just show the old and new version of the whole line (i.e. the kind of diff StackExchange shows you for edits to a post)?

I'd prefer one I could use on the Linux command line as diff in git.


Solution

  • You can try, from git diff:

    git diff --color-words=.
    

    Which is equivalent to --word-diff=color plus (if a regex was specified) --word-diff-regex=<regex>.

    That would transform this git diff:

    https://d262ilb51hltx0.cloudfront.net/max/800/1*DAIIfQVu0nLzgb7xw7mLjQ.png

    into this one:

    https://d262ilb51hltx0.cloudfront.net/max/800/1*Mb16aJnq46sv87QcYwZu-Q.png

    Images are from the section "Produce more useful diffs" of the article "30 Git CLI options you should know about" written in Sept. 2014 by Christophe Porteneuve.