git show --name-status字母:什么时候可以出现多个字母? [英] git show --name-status letters: when can more than one letter appear?

查看:92
本文介绍了git show --name-status字母:什么时候可以出现多个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关git的快速问题,尤其是 --diff-filter 字母,使用时出现

Quick question about git, specifically the --diff-filter letters, as they appear when using

git show< rev>--name-status --oneline

我注意到在某些文件中,我得到如下结果:

I notice that in some of files, I get results like:

AM contrib/platform/src/com/sun/jna/platform/win32/WinUser.java

AM contrib/platform/src/com/sun/jna/platform/win32/WinUser.java

怎么可能同时添加和修改了此文件?我也得到如下结果:

How is it possible that this file was both added and modified? I also get results such as:

MM CHANGES.md

MM CHANGES.md

这可能是由于提交承诺造成的吗?还有其他可能的原因吗?

Could this caused by an ammended commit? Are there any other possible causes?

谢谢

推荐答案

git show 命令可以显示合并提交和非合并提交.您正在显示合并.

The git show command can show merge commits as well as non-merge commits. You're showing a merge.

当您要求 git show 显示合并提交时,默认情况下它将使用组合差异".例如,这是git源本身的提交(一部分).我在这里使用 HEAD ^ ,因为此特定的合并提交恰好具有正确的更改类型,以产生有趣的结果.我将首先给出示例,然后解释发生了什么.

When you ask git show to show a merge commit, it uses a "combined diff" by default. For instance, here's (part of) a commit in the git source itself. I used HEAD^ here as this particular merge commit happens to have the right kind of changes to produce an interesting result. I will give the examples first, and then explain what's going on.

$ git show HEAD^
commit 4109c28e055dba27d73cefb956bea5e611f66ec0
Merge: a3d54f9 e09867f
Author: Junio C Hamano <gitster@pobox.com>
Date:   Tue Aug 26 11:16:26 2014 -0700

    Merge branch 'jk/diff-tree-t-fix'

让我们添加-name-status --oneline :

$ git show --name-status --oneline HEAD^
4109c28 Merge branch 'jk/diff-tree-t-fix'

MM      combine-diff.c
MM      t/t4038-diff-combined.sh

虽然我们只有 MM 而不是 AM .这看上去很像您.

This looks much like yours, although we just have MM rather than AM.

现在,我们添加 -m (这会很长,因此我将其剪短):

Now let's add -m (this gets long so I'll snip it down):

$ git show -m --name-status --oneline HEAD^
4109c28 (from a3d54f9) Merge branch 'jk/diff-tree-t-fix'
M       combine-diff.c
M       t/t4038-diff-combined.sh
4109c28 (from e09867f) Merge branch 'jk/diff-tree-t-fix'
M       .gitignore
M       .mailmap
[...]
M       column.c
M       combine-diff.c
M       command-list.txt
[...]

-m 的输出最容易解释.合并提交是具有两个或多个父级的提交,并且使用 -m 时, git show 命令按顺序显示每个父级的提交差异:

The output from -m is the easiest to explain. A merge commit is a commit with two or more parents, and with -m, the git show command shows a diff of the commit against each parent in sequence:

... - A - M
        /
... - B

此处合并提交 M (对于git源为 4109c28 ,此处)具有提交 A ( a3d54f9 )作为其第一个父项,而 B ( e09867f )作为其第二个父项.将 A 的内容与 M 进行比较,我们发现文件 combine-diff.c t/t4038-diff-binbined.sh 进行了修改.将 B 的内容与 M 进行比较,我们发现修改了许多文件,包括 combined-diff.c (并且,在输出中,我也删除了 t/t4038-diff-combined.sh ).

Here merge commit M (4109c28 in the case of the git sources, here) has commit A (a3d54f9) as its first parent, and B (e09867f) as its second. Comparing the contents of A with M, we find that files combine-diff.c and t/t4038-diff-combined.sh are modified. Comparing the contents of B with M, we find that many files are modified, including combined-diff.c (and, in output I snipped away, t/t4038-diff-combined.sh as well).

当git显示组合差异"时,它首先过滤掉所有未从两个父级更改的文件(对于3个或更多父级合并,则是所有父级").也就是说,将 column.c B 修改为 M 并不是有趣",因为它不是 A 修改为 M .但是 combined-diff.c 在两个单独的diff中都发生了变化,因此保留在组合的diff中.

When git shows a "combined diff", it first filters away all files that are not changed from both parents (or "all parents" for a 3-or-more parent merge). That is, it's not considered "interesting" that column.c was modified from B to M because it was not modified from A to M. But combined-diff.c was changed in both individual diffs, so it is retained in the combined diff.

如果添加-diff-filter ,则通过仅保留那些与过滤器匹配的差异,进一步减少了差异.

If you add --diff-filter, this reduces the diff even further, by retaining only those diffs that match the filter.

在任何情况下,组合的差异的状态"部分都显示为一系列状态-es,每个父项一个.这里的序列 AM 表示在合并和第一个父级之间添加了文件,而在合并和第二个父级之间添加了文件.您还可以获取 MM (如上例所示), MA (从第一个父级修改,从第二个父级添加), MT TM ,依此类推.我很公平,但不完全是,确保您不会看到重命名和副本(文档说没有分数,只显示一个路径,这对于重命名和复制是一个问题).在每种情况下,每个字母都有其通常的含义.在任何情况下,您都不会看到带有空格作为修改状态字母之一的情况,因为这意味着没有变化",并且由于从组合的差异中舍弃了某位父母没有变化".

In any case, the combined diff's "status" part is shown as a series of status-es, one for each parent. The sequence AM here means that between merge and first-parent, the file was added, while between merge and second-parent, the file was modified. You can also get MM (as in the example above), MA (modified from first parent, added from second), MT and TM, and so on. I'm fairly, but not completely, sure you will not see renames and copies (the documentation says that there are no score numbers and only a single path is shown, which would be a problem for rename and copy). In each case, each letter has its usual meaning. What you won't see here is any case with a space as one of the modified-status-letters, since that means "no change" and since "no change from some parent" is discarded from the combined diff.

有关组合差异的更多信息,请参见例如

For more about combined diffs, see the "COMBINED DIFF FORMAT" section of, e.g., the git diff-tree documentation.

这篇关于git show --name-status字母:什么时候可以出现多个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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