“怎么做?”;索引f2e4113..d4b9bfc 100644“;git中的diff与gitk中的SHA1 ID对应吗?

“怎么做?”;索引f2e4113..d4b9bfc 100644“;git中的diff与gitk中的SHA1 ID对应吗?,git,gitk,Git,Gitk,git diff输出中的“索引f2e4113..d4b9bfc 100644”是什么意思?到目前为止,我一直假设这些sha1id是从_版本..到_版本的,但我在gitk中找不到它们 $ git --version git version 1.8.3.4 $ git diff ae1fdc1 diff --git a/README b/README index f2e4113..d4b9bfc 100644 --- a/README +++ b/README @@ -1 +1,3 @@ stuff

git diff输出中的“索引f2e4113..d4b9bfc 100644”是什么意思?到目前为止,我一直假设这些sha1id是从_版本..到_版本的,但我在gitk中找不到它们

$ git --version
git version 1.8.3.4
$ git diff ae1fdc1
diff --git a/README b/README
index f2e4113..d4b9bfc 100644
--- a/README
+++ b/README
@@ -1 +1,3 @@
stuff
+more
+more stuff
“索引f2e4113..d4b9bfc 100644”看起来不像diff统一格式的一部分。

100644看起来像文件模式,但与自述文件(660)的模式不对应

f2e4113..d4b9bfc是SHA1 ID短裤。”git rev parse'给出了长SHA1。以下是上述示例中的三个短项:

ae1fdc1 - ae1fdc1e7b2f018a15c421f2f22b7c77215c5d61
d4b9bfc - d4b9bfcd51a3eaf427d337a30b12d1f3dbdd21b4
f2e4113 - f2e41136eac73c39554dede1fd7e67b12502d577
但为什么ae1fdc1不对应于差异的第一部分或第二部分?
为什么我不能用gitk找到d4b9bfc或d4b9bfc?

编辑:@wiswit已经指出了很好的解释

f2e4113
d4b9bfc
是文件索引。使用
git show f2e4113
可以看到提交前的文件,
git show d4b9bfc
显示提交后的文件

组合的diff格式在所描述的git diff手册页面中

COMBINED DIFF FORMAT
   Any diff-generating command can take the ‘-c` or --cc option to produce a 
   combined diff when showing a merge. This is the default format when showing 
   merges with git-diff(1) or git-show(1). Note also that you can give the `-m’
   option to any of these commands to force generation of diffs with individual 
   parents of a merge.

   A combined diff format looks like this:

       diff --combined describe.c
       index fabadb8,cc95eb0..4866510
       --- a/describe.c
       +++ b/describe.c
       @@@ -98,20 -98,12 +98,20 @@@
               return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
         }

       - static void describe(char *arg)
        -static void describe(struct commit *cmit, int last_one)
       ++static void describe(char *arg, int last_one)
         {
        +      unsigned char sha1[20];
        +      struct commit *cmit;
               struct commit_list *list;
               static int initialized = 0;
               struct commit_name *n;

        +      if (get_sha1(arg, sha1) < 0)
        +              usage(describe_usage);
        +      cmit = lookup_commit_reference(sha1);
        +      if (!cmit)
        +              usage(describe_usage);
        +
               if (!initialized) {
                       initialized = 1;
                       for_each_ref(get_name);

    1. It is preceded with a "git diff" header, that looks like this (when -c 
       option is used):

           diff --combined file

       or like this (when --cc option is used):

           diff --cc file

    2. It is followed by one or more extended header lines (this example shows
       a merge with two parents):

           index <hash>,<hash>..<hash>
           mode <mode>,<mode>..<mode>
           new file mode <mode>
           deleted file mode <mode>,<mode>

       The mode <mode>,<mode>..<mode> line appears only if at least one of the 
       <mode> is different from the rest. Extended headers with information 
       about  detected contents movement (renames and copying detection) are
       designed to work with diff of two <tree-ish> and are not used by combined
       diff format.

    3. It is followed by two-line from-file/to-file header

           --- a/file
           +++ b/file

       Similar to two-line header for traditional unified diff format, 
       /dev/null is used to signal created or deleted files.

    4. Chunk header format is modified to prevent people from accidentally
       feeding it to patch -p1. Combined diff format was created for review 
       of merge commit changes, and was not meant for apply. The change is 
       similar to the change in the extended index header:

           @@@ <from-file-range> <from-file-range> <to-file-range> @@@

       There are (number of parents + 1) @ characters in the chunk header for 
       combined diff format.

   Unlike the traditional unified diff format, which shows two files A and B
   with a single column that has - (minus — appears in A but removed in B),
   + (plus — missing in A but added to B), or " " (space — unchanged) prefix,
   this format compares two or more files file1, file2,... with one file X, 
   and shows how X differs from each of fileN. One column for each of fileN is
   prepended to the output line to note how X’s line is different from it.

   A - character in the column N means that the line appears in fileN but it
   does not appear in the result. A + character in the column N means that
   the line appears in the result, and fileN does not have that line (in 
   other words, the line was added, from the point of view of that parent).

   In the above example output, the function signature was changed from both
   files (hence two - removals from both file1 and file2, plus ++ to mean one 
   line that was added does not appear in either file1 nor file2). Also eight 
   other lines are the same from file1 but do not appear in file2 (hence 
   prefixed with +).

   When shown by git diff-tree -c, it compares the parents of a merge commit
   with the merge result (i.e. file1..fileN are the parents). When shown by 
   git diff-files -c, it compares the two unresolved merge parents with the 
   working tree file (i.e. file1 is stage 2 aka "our version", file2 is stage 
   3 aka "their version").
组合差分格式
任何diff生成命令都可以使用“-c”或--cc选项生成
显示合并时的组合差异。这是显示时的默认格式
与git diff(1)或git show(1)合并。还请注意,您可以给出“-m”
选择这些命令中的任何一个,以强制生成具有单个
合并的父对象。
组合的diff格式如下所示:
diff——组合描述.c
索引fabadb8,cc95eb0..4866510
---a/c
+++b/说明
@@@ -98,20 -98,12 +98,20 @@@
返回(a_日期>b_日期)-1:(a_日期==b_日期)?0 : 1;
}
-静态无效描述(字符*arg)
-静态void description(struct commit*cmit,int last_one)
++静态空描述(char*arg,int last_one)
{
+无符号字符sha1[20];
+结构提交*cmit;
结构提交列表*列表;
静态int初始化=0;
结构提交名称*n;
+if(get_sha1(arg,sha1)<0)
+用法(描述用法);
+cmit=查找\提交\引用(sha1);
+如果(!cmit)
+用法(描述用法);
+
如果(!已初始化){
初始化=1;
对于每个参考(获取名称);
1.它前面有一个“git diff”头,看起来像这样(当-c
选项(已使用):
diff——组合文件
或者类似这样(使用--cc选项时):
diff--cc文件
2.它后面是一个或多个扩展标题行(此示例显示
与两个父级的合并):
指数
模式
新文件模式
删除文件模式,
仅当至少有一个
与其他不同。包含信息的扩展标头
关于检测到的内容移动(重命名和复制检测)是
设计用于与两个diff一起工作,不用于组合
差异格式。
3.后面是两行“从文件/到文件头”
---档案
+++b/文件
类似于传统统一差分格式的两行标题,
/dev/null用于表示创建或删除的文件。
4.修改区块头格式,防止人员意外
将其馈送到修补程序p1。创建组合差异格式以供审查
合并提交更改的个数,而不是用于应用。更改为
与扩展索引标题中的更改类似:
@@@    @@@
在的区块标头中有(父级数+1)@个字符
组合差分格式。
与传统的统一diff格式不同,它显示两个文件A和B
对于具有-(减-出现在a中,但在B中删除)的单列,
+(加号-A中缺少但添加到B)或“(空格-未更改)前缀,
此格式将两个或多个文件file1、file2…与一个文件X进行比较,
并显示X与每个fileN的区别。每个fileN的一列为
在输出行前面加上前缀,以说明X的行与它的不同之处。
列N中的-character表示该行出现在fileN中,但它不存在
不会出现在结果中。N列中的+字符表示
该行显示在结果中,而fileN没有该行(在
换言之,从父对象的角度来看,添加了该行)。
在上面的示例输出中,函数签名从
文件(因此从file1和file2中删除两个,加上++表示一个)
添加的行既不出现在文件1中,也不出现在文件2中)。另外还有八行
其他行与文件1相同,但不出现在文件2中(因此
前缀为+。
当git diff tree-c显示时,它比较合并提交的父级
具有合并结果(即file1..fileN是父项)。当显示为
git diff files-c,它将两个未解析的合并父级与
工作树文件(即文件1是阶段2,又称“我们的版本”,文件2是阶段2
3(即“他们的版本”)。

现在,在理解了它是一个文件索引之后,我在gitk中也看到了这个索引。也可以使用下面的搜索字段(而不是SHA1 ID字段)来搜索它谢谢。没问题:-)当这是答案时,请用绿色符号将其标记为答案。Thx!原始问题中的差异不是组合差异,只是一个常规的git风格差异。之所以使用
模式
100644
而不是
660
100660
是因为git只存储一位文件
rwx
模式,特别是
x
位。工作副本的模式基于存储的位加上用户的
umask
设置。差异字符串始终为
100644