How to use --color-words with git add --patch?

前端 未结 7 1790
梦谈多话
梦谈多话 2020-12-07 17:27

When diffing files, I prefer to use git diff --color-words. Is there a way to make this the default format for diffs when using git add --patch or

相关标签:
7条回答
  • 2020-12-07 18:20

    Building off of what VonC said:

    Starting with Git 2.9, you can use this command to color words during add --patch:

    git -c interactive.diffFilter="git diff --color-words" add -p
    

    This sets the interactive.diffFilter variable for the call to add -p without affecting further calls. For me this is ideal because I usually want to run add -p normally, but sometimes want to run it with --color-words.

    You can easily add an alias for this command like so:

    git config --global alias.addcw '-c interactive.diffFilter="git diff --color-words" add -p'
    
    0 讨论(0)
提交回复
热议问题