How to filter git diff based on file extensions?

后端 未结 10 1174
终归单人心
终归单人心 2020-12-02 05:43

Is there an option to restrict git diff to a given set of file extensions?

相关标签:
10条回答
  • 2020-12-02 06:26

    For simple file patterns, this seems to work:

    $ git ls-files -zm '*.txt' | xargs --null git diff
    

    Whitespace safe, and you can have multiple extensions too:

    $ git ls-files -zm '*.h|*.c|*.cpp' | xargs --null git diff
    
    0 讨论(0)
  • 2020-12-02 06:28

    Yes, if you ensure that git expands a glob rather than your shell then it will match at any level so something like this (quotes are important) should work fine.

    git diff -- '*.c' '*.h'
    
    0 讨论(0)
  • 2020-12-02 06:28

    To include files recursively (including current dir) this worked for me:

    git diff -- '***.py'
    
    0 讨论(0)
  • 2020-12-02 06:28

    Attention that params order makes difference...for example:

    git diff master --name-only --relative -- "**/*.ts" "**/*.tsx" "**/*.js" "**/*.jsx" "**/*.vue"
    

    'diff' need to be followed with 'master'

    0 讨论(0)
提交回复
热议问题