【问题标题】:git diff unique to merge commitgit diff 唯一的合并提交
【发布时间】:2011-10-06 12:27:13
【问题描述】:

说我有,

      A topic
     / \
D---E---F master

我可以很容易地得到 D-E 的差异

git diff D..E --name-status

同样适用于 E-F 和 E-A。

Commit F 是一个合并提交,并说它有冲突。已通过修改 foo.bar 解决。 foo.bar 被 git 添加,然后合并提交被提交。合并冲突已解决。

现在 foo.bar 的更改仅存在于提交 F 中。我如何获得该差异?

有没有办法获取合并提交中唯一引入的文件的差异?

【问题讨论】:

    标签: git merge diff commit


    【解决方案1】:

    不确定“在合并提交中唯一引入的文件”究竟是什么意思。该文件之前必须存在,否则不会发生冲突。并且“foo.bar 的更改仅存在于提交 F 中”也不完全正确。提交不包含更改。您可以看到 foo.bar 差异与其他任何差异完全相同:git diff E Fgit diff A F,具体取决于您要遵循的分支。

    【讨论】:

      【解决方案2】:

      git show 合并提交将显示其任何父项中没有的更改。例如:

      $ echo 123 > file1.txt
      $ git add file1.txt
      $ git commit -am '123'
      
      $ git checkout -b test
      $ echo 1234 > file1.txt
      $ git commit -am '1234'
      
      $ git checkout HEAD~ -b test2
      $ echo 0123 > file1.txt
      $ git commit -am '0123'
      
      $ git merge test
      $ echo 01234 > file1.txt
      $ git add file1.txt
      $ git commit -am 'Merge test'
      
      $ git show
      commit f056a1c91d76c8dfce60a03122494dce92c1e161
      Merge: 489f1d3 fcfd2bc
      Date:   Fri Jul 15 20:30:17 2011 -0500
      
          Merge test
      
      diff --cc file1.txt
      index 40381e2,81c545e..3521a84
      --- a/file1.txt
      +++ b/file1.txt
      @@@ -1,1 -1,1 +1,1 @@@
      - 0123
       -1234
      ++01234
      

      【讨论】:

        猜你喜欢
        • 2020-02-15
        • 1970-01-01
        • 2019-08-22
        • 2011-06-03
        • 2013-07-07
        • 2013-06-20
        • 2019-02-14
        • 2017-04-14
        • 2012-08-31
        相关资源
        最近更新 更多