git show在合并提交时给出令人困惑的结果

时间:2019-06-19 19:16:59

标签: git

我一直了解[tmux-master]# ./configure && make ... configure: error: "libevent not found" 从不对合并提交显示差异。可能出于同样的原因,git show在合并提交上未显示差异。但是,我能够创建两种可重现的方案:一个合并提交,确实产生一个与git log -p的差异,而另一个没有。我想了解为什么在这些情况下git show的行为会有所不同。

首先,这是我运行的脚本,该脚本创建了观察上述两种情况所需的存储库:

git show

场景1:#!/usr/bin/env bash set -ex git init test_repo cd test_repo # master (commit 1) printf "one\n" > file.txt git add file.txt git commit -m one # master (commit 2) printf "two\n" >> file.txt git commit -am two # master (commit 3) printf "three\n" >> file.txt git commit -am three # topic1 (commit 1) git checkout -b topic1 @^ printf "four\n" >> file.txt git commit -am four # merge topic1 to master (commit 4) git checkout master git merge - || true # conflict printf "one\ntwo\nthree\nfour\n" > file.txt git add file.txt git commit --no-edit git tag merge1 # tag so we can refer to it in examples # master (commit 5) printf "five\n" >> file.txt git commit -am five # topic2 (commit 1) git checkout -b topic2 printf "six\n" >> file.txt git commit -am six # merge topic2 to master (commit 6) git checkout master git merge --no-edit - # no conflict git tag merge2 # tag so we can refer to it in examples 显示了一个差异:

git show

场景2:$ cd test_repo $ git show merge1 commit cb7aba11aed80917e3fac64e60aef3fe0a27e5de (tag: merge1) Merge: 75bae65 5f63df7 Author: John Doe <john.doe@domain.com> Date: Wed Jun 19 14:05:34 2019 -0500 Merge branch 'topic1' # Conflicts: # file.txt diff --cc file.txt index 4cb29ea,87a123c..f384549 --- file.txt +++ file.txt @@@ -1,3 -1,3 +1,4 @@@ one two +three + four 不会显示差异:

git show

这两种情况(例如$ cd test_repo $ git show merge2 commit 5f37be9b563afc9c9f43ad04198d80809e6fc13a (HEAD -> master, tag: merge2) Merge: 6f4cf36 bde33e8 Author: John Doe <john.doe@domain.com> Date: Wed Jun 19 14:05:34 2019 -0500 Merge branch 'topic2' merge1)之间的主要区别是merge2指的是merge2^topic2的合并基础(之前(合并)和master是唯一的非合并提交。我不确定中间提交和合并提交之间的中间提交是否重要,但我想不出其他任何可能。谁能解释这种行为差异?

我期望merge1^不显示差异。就我而言,git show merge1的输出是正确的,而git show merge2的输出是不正确的(越野车)。

Windows上的Git版本是2.22.0。

2 个答案:

答案 0 :(得分:1)

git show默认情况下会产生组合差异。 (这是对git log -p的改进,对于合并提交,默认情况下完全不产生差异 !)

在两个单独的部分(在各个git diff命令手册页中分别显示)中记录了组合差异(在我看来有点差)。这是git diff-tree文档中的两个关键部分:

靠近底部的第一部分有此警告:

  

请注意,组合差异仅列出从所有父级修改而来的文件。

这应该是粗体字,18点字体和/或闪烁,并且不是,与告诉您如何读取输出的 second 部分相距甚远。 (-p描述在这两者之间有其自己的部分。此外,第一部分讨论的是模式行内容,但是实际上省略了许多文件这一事实适用于第二部分,只是未提及< em>在第二部分。)

我认为这里的目标是使默认的git show输出向您显示有人可能必须进行冲突解决的地方。通常这是个好主意,但有时您确实想要git show -m,它只显示与第一个父对象的差异,然后显示与第二个父对象的差异。

答案 1 :(得分:0)

如果有冲突解决方法,

git show将显示差异内容。