git diff 是合并提交所特有的

发布于 2024-11-24 01:17:04 字数 336 浏览 2 评论 0原文

假设我有,

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

执行相同的操作轻松获得 DE 的差异

git diff D..E --name-status

我可以通过对 EF 和 EA

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

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

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

Say I have,

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

I can easily get the diff of D-E by doing

git diff D..E --name-status

and same for E-F, and E-A.

Commit F is a merge commit, and say it had a conflict. It was resolved by modifying foo.bar. foo.bar was git added, then the merge commit was committed. The merge conflict was resolved.

Now the change for foo.bar exists only in commit F. How do I get that diff?

Is there a way to get the diff of files that were uniquely introduced in a merge commit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浸婚纱 2024-12-01 01:17:04

合并提交上的 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

git show on the merge commit will show changes not in any of its parents. For example:

$ 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
无戏配角 2024-12-01 01:17:04

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

Not sure exactly what "files that were uniquely introduced in a merge commit" means. The file had to exist before, or there wouldn't have been a conflict. And "the change for foo.bar exists only in commit F" isn't exactly correct, either. Commits don't contain changes. You can see the foo.bar diff exactly the same as any other: git diff E F or git diff A F, depending on which branch you want to follow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文