Reputation: 9845
Is there any option for git diff
that allows to just consider hunks that match some specific criteria (e.g. a regular expression)?
I want diff to just show me hunks that, for example, start with line matching the regex .*<<<special_diff.*
and end with a line matching the regex .*\sspecial_diff>>>
I am looking for solutions that would allow to do that, keeping performance fast and staying simple.
Note: it should be able to match multiple lines, so that I could match (into a hunk) a multiline block of text between specific delimiters.
Matching just if a hunk contains a full block (open + close delimiters); for example matching a multiline block delimited by <body>
and </body>
.
Upvotes: 5
Views: 1137
Reputation: 94912
Use git diff -Gregexp
. Example: the commit 5c6d3a9@mimedecode contains 3 hunks. If I run git diff 5c6d3a9~ 5c6d3a9
I see all 3.
I can filter them using git diff -GReplaced 5c6d3a9~ 5c6d3a9
and I see only 2 of these 3 hunks. With git diff -Greplaced 5c6d3a9~ 5c6d3a9
nothing is shown because by default regexp searching is case-sensitive. To make it case-insensitive add -i
: git diff -Greplaced -i 5c6d3a9~ 5c6d3a9
; this again produces 2 hunks.
Upvotes: 0