Git Diff标头上的数字是什么意思? [英] What do the numbers on a Git Diff header mean?

查看:178
本文介绍了Git Diff标头上的数字是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次运行git diff时,对于所做的每个更改,我都会得到带有数字的标头,例如:

Every time I run git diff, for each single changes I made, I get some sort of header with numbers, for example:

@@ -169,14 +167,12 @@ function Browser(window, document, body, XHR, $log) {.....

我想知道这四个数字是什么意思?我猜-169意味着后面的这一特定代码行原本在169行中,但现在在167行中? 14和12是什么意思?

I wonder what does the four numbers mean? I guess -169 means that this particular line of code that follows was originally in line 169 but now is in 167? And what do 14 and 12 mean?

推荐答案

这个 header 被称为变更集或大块。每个大块都以一行开头,该行包含@@中的行或行范围 from,no-of-lines 之前的行(-)和更改之后(带有 + )。之后,来自文件的行。删除以-开头的行,并添加以 + 开头的行。补丁修改的每一行前后都有3条上下文。

This header is called set of change, or hunk. Each hunk starts with a line that contains, enclosed in @@, the line or line range from,no-of-lines in the file before (with a -) and after (with a +) the changes. After that come the lines from the file. Lines starting with a - are deleted, lines starting with a + are added. Each line modified by the patch is surrounded with 3 lines of context before and after.

附加内容如下:

@@ -75,6 +103,8 @@
 foo
 bar
 baz
+line1
+line2
 more context
 and more
 and still context

这意味着,在原始文件的第78行(= 75 + 3行上下文)之前添加两行。在所有更改之后,这些将是从106行(= 103 + 3行上下文)到107行。

请注意数字之间的差异(-75与+103),这意味着此文件之前,此文件还有其他更改,增加了28(103-75)行代码。

That means, in the original file before line 78 (= 75 + 3 lines of context) add two lines. These will be lines 106 (= 103 + 3 lines of context) through 107 after all changes.
Note the difference in from numbers (-75 vs +103), this means that there were other changes in this file before this particular hunk, that added 28 (103 - 75) lines of code.

A删除看起来像这样:

@@ -75,7 +75,6 @@
 foo
 bar
 baz
-line1
 more context
 and more
 and still context

这意味着删除原始文件中的第78行(= 75 + 3行上下文)。所有更改后,不变的上下文将位于75到80行上。

请注意,此块中的 from 个数字相等(-75和+75) ,这意味着要么在此请求之前没有更改,要么以前更改中添加和删除的行数相同。

That means, delete line 78 (= 75 + 3 lines of context) in the original file. The unchanged context will be on lines 75 to 80 after all changes.
Note that from numbers in this hunk are equal (-75 and +75), this means that either there were no changes before this hunk, or amount of added and deleted lines in previous changes are the same.

最后,更改看起来像这样:

@@ -70,7 +70,7 @@
 foo
 bar
 baz
-red
+blue
 more context
 and more
 still context

这意味着在所有更改之前更改文件中的第73行(= 70 + 3行上下文),其中包含红色到蓝色。所有更改之后,更改后的行也是文件中的第73行(= 70 + 3行上下文)。

That means, change line 73 (= 70 + 3 lines of context) in the file before all changes, which contains red to blue. The changed line is also line 73 (= 70 + 3 lines of context) in the file after all changes.

信用归Markus Bertheau

这篇关于Git Diff标头上的数字是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆