gitgit-diff

In a Git diff, can I exclude diffs that contain certain strings?


With Git diff, is there a way to exclude lines that contain a given string? (A parallel, of sorts, is to exclude diffs containing only white spaces with -w.) Sometimes a Git diff returns long lists of changes that are not meaningful at a given stage of development.

For example, patches that change only UUIDs, or those that change only 'weight'. At times these changes are not significant, but nonetheless result in diffs containing many, many lines.

The Git documentation seem to mention features close to exclusion by string (git grep and git log -L). Is there something out there that I've not yet found, or that I've just not yet used correctly?


Solution

  • Answer from the doc page on Git-diff

    -I<regex>
    --ignore-matching-lines=<regex>
    
        Ignore changes whose all lines match <regex>. This option may be specified more than once.
    

    Example putting it to use

    git diff -I"^uuid: " -- config/sync will return a succinct list that ignores the changes in any line starting with 'uuid: '.