Git diff - ignore reorder

前端 未结 2 1181
星月不相逢
星月不相逢 2021-01-11 20:29

git diff numbers

diff --git a/numbers b/numbers
index 5f5fbe7..d184fef 100644
--- a/numbers
+++ b/numbers
@@ -1,3 +1,3 @@
-1
+4
+3
 2
-3

Nu

2条回答
  •  -上瘾入骨i
    2021-01-11 20:45

    The diffing tools are usually implemented in terms of the Myers' diff algorithm. There isn't much that you can do to control the behaviour of GNU/git/diff. (There are a couple of switches that you can pass to diff to affect the behaviour, but in your case they are irrelevant.)

    You could simply post-process the output and remove the duplicate lines, for example you can pipe your diff through the following awk script that will remove (duplicate) -/+ reordering.

    git diff | awk '{ seen[substr($0,2)]++; l[i++] = $0; } END { for (j = 0; j < i; ++j) if (seen[substr(l[j],2)] < 2) print l[j] }'
    

    For your example, the output would be,

    diff --git a/numbers b/numbers
    index 5f5fbe7..d184fef 100644
    --- a/numbers
    +++ b/numbers
    @@ -1,3 +1,3 @@
    -1
    +4
     2
    

提交回复
热议问题