ignoring changes matching a string in git diff

前端 未结 4 1276
不思量自难忘°
不思量自难忘° 2020-12-08 06:53

I\'ve made a single simple change to a large number of files that are version controlled in git and I\'d like to be able to check that no other changes are slipping into thi

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 07:30

    Use git difftool to run a real diff.

    Example: https://github.com/cben/kubernetes-discovery-samples/commit/b1e946434e73d8d1650c887f7d49b46dcbd835a6
    I've created a script running diff the way I want to (here I'm keeping curl --verbose outputs in the repo, resulting in boring changes each time I rerun the curl):

    #!/bin/bash
    diff --recursive --unified=1 --color \
         --ignore-matching-lines=serverAddress \
         --ignore-matching-lines='^\*  subject:' \
         --ignore-matching-lines='^\*  start date:' \
         --ignore-matching-lines='^\*  expire date:' \
         --ignore-matching-lines='^\*  issuer:' \
         --ignore-matching-lines='^< Date:' \
         --ignore-matching-lines='^< Content-Length:' \
         --ignore-matching-lines='--:--:--' \
         --ignore-matching-lines='{ \[[0-9]* bytes data\]' \
         "$@"
    

    And now I can run git difftool --dir-diff --extcmd=path/to/above/script.sh and see only interesting changes.

    An important caveat about GNU diff -I aka --ignore-matching-lines: this merely prevents such lines from making a chunk "intersting" but when these changes appear in same chunk with other non-ignored changes, it will still show them. I used --unified=1 above to reduce this effect by making chunks smaller (only 1 context line above and below each change).

提交回复
热议问题