Git diff-忽略重新排序 [英] Git diff - ignore reorder
问题描述
git diff数字
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
重复数字3,但是顺序被更改. 有什么方法可以忽略git或任何grep解决方案中的重新排序? 我只想要添加和删除数字的结果,而不希望对相同数字进行重新排序 有帮助吗?
Number 3 is repeated but the order is changed. Any way to ignore the reorder in git or any grep solution? I want the result of only added and deleted numbers, not reordering of the same numbers Any help?
推荐答案
差异工具通常是根据Myers的差异算法实现的.您可以做很多事情来控制GNU/git/diff的行为. (您可以将几个开关传递给diff,以影响其性能,但对于您而言,它们是无关紧要的.)
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.)
您可以简单地对输出进行后处理并删除重复的行,例如,您可以通过以下awk脚本来传递差异,该脚本将删除(重复)-/+重新排序.
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] }'
对于您的示例,输出为
diff --git a/numbers b/numbers
index 5f5fbe7..d184fef 100644
--- a/numbers
+++ b/numbers
@@ -1,3 +1,3 @@
-1
+4
2
这篇关于Git diff-忽略重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!