首页 Git diff输出格式之unified format
文章
取消

Git diff输出格式之unified format

diff Output Formats

Context Format(-c)

The context output format shows several lines of context around the lines that differ. It is the standard format for distributing updates to source code.

-c选项时,这种对比文件时,感觉不是很直观;主要的场景是,用diff来生成代码补丁,代码差异行上下有上下文,方便补丁程序patch来进行差异代码定位

Unified Format(-U)

The unified output format is a variation on the context format that is more compact because it omits redundant context lines.

-u选项时,这种对比文件时,感觉还比较方便看;官方定义如上,即该格式是context format的变体,因为省略了冗余的上下文行,显得更加紧凑

Unified Format Introduction

Image.png

文件列表

1
2
--- a/test.txt
+++ b/test2.txt

差异段列表

@@ 这一行,表示一个汇总信息,其中的-4,其实应该是-4,1。 “-“代表文件--- a/test.txt,4代表第四行,test.txt的第4行,就是4444444444444444444这一行,被省略的1,表示展示的text.txt从第4行开始的行的数量。

比如,4,2表示展示第4、5行,4,3表示展示第4、5、6行。

+4,2同理,”+”代表文件+++ a/test2.txt,也就是展示4开头的两行,即第4、5行。

1
2
3
4
@@ -4 +4,2 @@
-4444444444444444444
+4444444448878784444444444
+insert1
  • ‘+’: A line was added here to the first line
  • '-': A line was removed here from the first file
  • space character: The lines common to both files
本文由作者按照 CC BY 4.0 进行授权

Myers Diff Algorithm

MySQL中EXPLAIN输出type列解析