Search code examples
gitgit-diffgit-patch

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


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


Solution

  • 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.