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

江枫思渺然 提交于 2019-12-05 07:46:46

问题


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.


回答1:


You can try, from git diff:

git diff --color-word=.

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

That would transform this git diff:

into this one:

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.



来源:https://stackoverflow.com/questions/28505175/how-can-i-make-git-diff-as-fine-grained-as-stackexchange-diff

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!