Can I make git add -p show changes like git diff --word-diff?

你说的曾经没有我的故事 提交于 2019-12-06 22:22:57

问题


I have recursively replaced many single word patterns in my code base. Before committing I need to check each for false replacements. It would help me a lot to have git add -p use the format of what --word-diff uses with git diff, where only the changed words are marked and not the entire line.

Someone has asked the same here, but maybe it was implemented since? https://groups.google.com/forum/#!topic/git-users/7uO2OUJGvP0


回答1:


Since Git 2.9, you can use the property interactive.diffFilter (as I mentioned below this answer)

But, any git -c interactive.diffFilter="git diff --color-words" add -p would generate, since Git 2.17, an error message

fatal: mismatched output from interactive.diffFilter

(as seen in this question)

So using a script for the interactive.diffFilter setting remains a safer way.




回答2:


Adding diff-highlight to the interactive.diffFilter config key is the easiest option (since Git 2.9). The following comand does the trick on Debian/Ubuntu:

git config interactive.diffFilter "perl /usr/share/doc/git/contrib/diff-highlight/diff-highlight"

Things like git -c interactive.diffFilter="git diff --color-words" add -p or git config interactive.diffFilter "git diff --color-words" don't work properly: add -p always keeps suggesting the first modified file.



来源:https://stackoverflow.com/questions/44218326/can-i-make-git-add-p-show-changes-like-git-diff-word-diff

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