“@@ -1 +1 @@”在 Git 的差异输出中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10950412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:53:14  来源:igfitidea点击:

What does "@@ -1 +1 @@" mean in Git's diff output?

gitdiff

提问by SSEMember

I've been collecting data from the information returned from

我一直在从返回的信息中收集数据

git diff <commitId>..<commitId>

and I ran into @@ -1 +1 @@

我遇到了 @@ -1 +1 @@

I can't figure out what that's telling me. I've searched a bit on Google but to no avail.

我无法弄清楚这在告诉我什么。我在谷歌上搜索了一下,但无济于事。

采纳答案by Todd A. Jacobs

It's a unified diff hunk identifier. This is documentedby GNU Diffutils.

这是一个统一的差异大块标识符。这是记录由GNU diffutils的。

The unified output format starts with a two-line header, which looks like this:

--- from-file from-file-modification-time
+++ to-file to-file-modification-time

The time stamp looks like 2002-02-21 23:30:39.942229878 -0800to indicate the date, time with fractional seconds, and time zone. The fractional seconds are omitted on hosts that do not support fractional time stamps.

You can change the header's content with the --label=labeloption; see See Alternate Names.

Next come one or more hunks of differences; each hunk shows one area where the files differ. Unified format hunks look like this:

@@ from-file-line-numbers to-file-line-numbers @@
 line-from-either-file
 line-from-either-file...

If a hunk contains just one line, only its start line number appears. Otherwise its line numbers look like start,count. An empty hunk is considered to start at the line that follows the hunk.

If a hunk and its context contain two or more lines, its line numbers look like start,count. Otherwise only its end line number appears. An empty hunk is considered to end at the line that precedes the hunk.

The lines common to both files begin with a space character. The lines that actually differ between the two files have one of the following indicator characters in the left print column:

  • +
    A line was added here to the first file.
  • -
    A line was removed here from the first file.

统一输出格式以两行标题开头,如下所示:

--- from-file from-file-modification-time
+++ to-file to-file-modification-time

时间戳看起来像是2002-02-21 23:30:39.942229878 -0800指示日期、带小数秒的时间和时区。在不支持小数时间戳的主机上省略小数秒。

您可以使用该--label=label选项更改标题的内容;请参阅备用名称

接下来是一个或多个差异;每个大块显示文件不同的一个区域。统一格式看起来像这样:

@@ from-file-line-numbers to-file-line-numbers @@
 line-from-either-file
 line-from-either-file...

如果一个大块只包含一行,则只显示它的起始行号。否则它的行号看起来像. 一个空的大块被认为是从大块后面的那一行开始。start,count

如果一个大块和它的上下文包含两行或更多行,它的行号看起来像. 否则只显示其结束行号。一个空的大块被认为在大块之前的行结束。start,count

两个文件共有的行以空格字符开头。两个文件之间实际不同的行在左侧打印列中具有以下指示符之一:

  • +
    在第一个文件中添加了一行。
  • -
    此处从第一个文件中删除了一行。

回答by Yuval Adam

It's the current hunk range information stating on which line numbers this diff hunk starts and ends.

这是当前大块范围信息,说明此差异大块开始和结束的行号。

Read http://en.wikipedia.org/wiki/Diff#Unified_formatfor an in-depth explanation.

阅读http://en.wikipedia.org/wiki/Diff#Unified_format以获得深入的解释。