我可以强制git将变更视为单件吗?

偶尔我会有一个完全重写代码块的提交,但有几个相同的行偶然穿插.
Git-diff将变化分成围绕这些线的碎片,差异变得难以理解.

在这种情况下,最好告诉git“忽略单个未更改的行;就像删除并替换整个块一样.”

例如,我想转变一个看起来像这样的差异:

-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

进入这个:

-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

有没有办法在准备提交或稍后查看日志时这样做?

最佳答案 diff.interHunkContext的配置说

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.

看起来就像你想要的那样.

点赞