Reputation: 4428
Occasionally I'll have a commit that completely rewrites a block of code, but has a few identical lines interspersed by chance. Git-diff divides the change into pieces around those lines, and the diff becomes hard to understand.
In such cases it would be nice to tell git "ignore single unchanged lines; act as if this entire block was deleted and replaced."
For example, I want to turn a diff that looks like this:
-def rewritten_function(oldarg):
- do a
- do b
+def rewritten_function(newarg):
+ do z
+ do y
with random_matching_line as f:
- do x
- do y
- do z
+ do a
+ do b
+ do c
into this:
-def rewritten_function(oldarg):
- do a
- do b
- with random_matching_line as f:
- do x
- do y
- do z
+def rewritten_function(newarg):
+ do z
+ do y
+ with random_matching_line as f:
+ do a
+ do b
+ do c
Is there a way to do that, either when preparing a commit or viewing the log later?
Upvotes: 4
Views: 70
Reputation: 60635
diff.interHunkContext
's config says
Show the context between diff hunks, up to the specified number of lines, thereby fusing the hunks that are close to each other. This value serves as the default for the
--inter-hunk-context
command line option.
which looks like exactly what you want.
Upvotes: 1