- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 git 存储库中有一个提交,其中 git show
说只有一个文件被修改,而 git diff
显示两个文件被修改。
我创建了一个简单的示例存储库,它表现出相同的行为。
在示例存储库中,我们有这个简单的历史:
* c248261 (HEAD, origin/master, master) Merged feature into master.
|\
| * d23c497 (feature) Modified fileA and fileB in feature.
* | 06a7f5e Modified fileA and fileC in master.
* | 9cd1a6e Merged feature into master.
|\ \
| |/
| * aed2e5e Modified fileA and fileB in feature.
* | c6e4fe7 Mofified fileC in master.
* | 19ed298 Merged feature to master.
|\ \
| |/
| * c0f2abc Added fileB and modified fileA in feature.
* | 47c67cf Added fileC in master.
|/
* 56a9b73 Added fileA in master.
例如,当我查看提交 c248261 时SourceTree,我可以看到 fileA
和 fileB
被修改了。使用 git diff
得到相同的结果:
$ git diff --name-only c248261^..c248261
fileA
fileB
$
或使用速记符号:
$ git diff --name-only c248261^!
fileA
fileB
$
当我尝试使用 git show
获取相同的信息时,只显示了两个文件之一:
$ git show --name-only c248261
commit c2482616b6b6781d0580ec1008ef7d0ab5f73a70
Merge: 06a7f5e d23c497
Author: ...
Date: Fri Aug 15 16:19:02 2014 +0200
Merged feature into master.
fileA
$
同样,git diff-tree
什么也没显示:
$ git diff-tree c248261
$
有人能解释一下区别吗?
我使用的是 git 版本 2.0.4。
最佳答案
git show
?命令 git show
是一个通用命令,用于显示有关 git
中对象的信息。
来自手册页(git help show
):
Shows one or more objects (blobs, trees, tags and commits).
...
For commits it shows the log message and textual diff.
It also presents the merge commit in a special format as produced by
git diff-tree --cc
...
因此,git show
的输出是不同的,因为这是一个merge 提交而不是一个plain 提交。
git diff-tree --cc
的手册页说:
--cc
This flag changes the way a merge commit patch is displayed, in a
similar way to the -c option. It implies the -c and -p options and
further compresses the patch output by omitting uninteresting hunks whose
the contents in the parents have only two variants and the merge result
picks one of them without modification. When all hunks are uninteresting,
the commit itself and the commit log message is not shown, just like in
any other "empty diff" case.
进一步
-c
This flag changes the way a merge commit is displayed (which means
it is useful only when the command is given one <tree-ish>, or
--stdin). It shows the differences from each of the parents to the
merge result simultaneously instead of showing pairwise diff
between a parent and the result one at a time (which is what the -m
option does). Furthermore, it lists only files which were modified
from all parents.
请注意我在这里重复的最后一行:
Furthermore, it lists only files which were modified from all parents.
因此 git show
merge 提交将仅列出在将提交与 merge 的所有 父项进行比较时修改的文件。对于普通 merge (即 2 个父项),这正是被 merge 的文件。例如,如果您执行此 merge :
git checkout master
git merge feature
git show
列出的文件是在 master
和 feature
之前修改的文件 merge 并在 merge 提交中 merge 在一起。
对于 Octopus merge ——即超过两个父项——生成的文件必须不同于 所有 父项中的文件才能被 git show
显示。
请注意,在 merge 提交中使用 git show
时,其他文件也可能会显示。例如,如果您调用 git merge --no-commit
然后在提交之前执行以下任何操作,那么这些文件也将被 git show
显示在 merge 提交:
git show
正在做的是显示一个所谓的组合差异。
在 merge 提交上运行命令 git show
的结果可以被认为是只显示 merge 的文件,而不是简单地从两个父项之一中获取的未更改文件。
这有点令人惊讶,因为许多人希望看到与您刚刚 merge 到的分支相比哪些文件被修改了。
那么,如果您想查看 parent 双方的差异怎么办?
让我们最后看一下 git show
的手册页:
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.
所以我们可以使用 -m
选项来获得两个差异,如下所示:
git show -m commit
这将一一为您提供与所有 parent 的差异。
要查看 merge 提交与您 merge 到的分支(即第一个父级)上的先前提交之间的区别,请使用以下任一命令:
git show --first-parent commit
git diff commit^..commit
git diff commit^!
--first-parent
选项确实属于 git log
但也适用于 git show
。符号 commit^!
是 commit^..commit
的简写。
要查看 merge 提交和您 merge 的分支之间的区别(例如,查看您从其他分支遗漏的内容),使用
git diff commit^2..commit
符号 commit^2
表示 commit
的第二个父级。
如果您有超过 2 个父项(即 Octopus merge ),我相信您可以猜出如何与第 3、4 等提交进行比较。
关于git - “git show” 不返回与 “git diff” 相同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325348/
我在我们的系统中使用了多种不同的查询,我们想要获取分页的“总”记录。 我所遵循的所有地方都遵循这种结构 - var query1 = "select SQL_CALC_FOUND_ROWS ...."
我是 diff 的新手。我过去用过它。但我想知道,是否可以使用 diff 来跟踪希伯来语中两个文件之间的差异?我想比较具有元音点和重音符号的圣经希伯来文文件。 最佳答案 我不知道有任何“差异”(文件比
在Word中,有一个选项可以比较两个文档并找出两个文档之间的差异。我正在寻找一个类似的功能来比较两个Powerpoint文档。理想情况下,它将列出不同的单个幻灯片,每个幻灯片之间版本之间的差异以及进行
Bizzaro-Diff!!! 有没有办法做一个只显示一组文件中相同部分的 bizzaro/inverse-diff? (即远超过 three files ) 奇怪的问题,我知道...但我正在将某人的
我将 git 与默认的 Ubuntu 12.04 软件包一起使用: git --version git version 1.7.9.5 我找不到任何可以让 git diff 打开外部差异工具的机制,它
这是我的树 ├── test │ ├── dir1 │ └── dir2 │ ├── file │ └── file2 └── test2 └── dir2
我在 source forge ( cocoa.diff ) 上找到了这个补丁,这意味着我可以使用 cocoa.diff 文件进行补丁。但是,我似乎无法弄清楚如何使用 .diff 文件。 谢谢你的帮助
我修改了某个文件的第 494 行,并使用 cvs diff -u4 来查看我修改的内容,cvs 输出如下内容: @@ -490,9 +490,9 @@ if (!(hPtr->hSta
我需要知道这两个补丁是否有效相同。 我有一个旧补丁文件和使用 unix diff 命令创建的新补丁文件。由于补丁创建时的时间戳,只是比较补丁会报告差异。 有没有办法(有差异?)可以可靠地告诉我这两个补
我有这样的东西 src/sim/simulate.cc 41d40 public: > 61,62c60,61 a.patch 用于创建补丁文件,尽管也可能会抛出一些其他开关(-N?)
我想知道是否有工具可以显示与 debian 打包相关的补丁中使用的 *.diff 文件。我需要从该工具中获得的是它可以只读取 diff 文件并显示随更改的行更改的实际文件,就像 kdiff 或 mel
主要有3个git diff版本: git diff - difference between WORKING DIRECTORY & STAGE git diff --staged - differe
根据 Ender 的 Applied Econometric Time Series ,变量 y 的二阶差分定义为: Pandas 提供了 diff 函数,它接收“periods”作为参数。尽管如此,
这是我的差异的开始部分。 #!/usr/bin/env python import fileinput import difflib import subprocess import sys # fo
有没有办法在 svn diff 或任何其他工具(基于 linux)到 仅显示空格/制表符更改 ?. 目的,我不希望 checkin 这些差异。如果工具可以捕获这些差异,我可以在 checkin 之前将
我正在尝试比较忽略回车符的文件 - diff -b 在任何其他 unix 上的表现令人钦佩。但是在这个 AIX 5.3 机器上: tst1:tst2$ od -c testfile 00000
这个问题已经有答案了: What does the “@@…@@” meta line with at signs in svn diff or git diff mean? (3 个回答) 已关闭
我在使用 git diff --word-diff 时遇到了问题。问题是当 diff 获取没有换行符的文件(单行文件)时,它会逐行区分。我想逐字区分。 以下是当我在没有换行符的情况下比较文件时发生的情
这个问题在这里已经有了答案: Highlight changed lines and changed bytes in each changed line (12 个答案) 关闭 7 年前。 给定一
我正在尝试使用两个大文件夹(〜7GB)创建一个补丁。 这是我的做法: $ diff -Naurbw . ../other-folder > file.patch 但可能由于文件大小而导致未创建补丁并给
我是一名优秀的程序员,十分优秀!