提交之间存在差异,但git log不显示更改 [英] Difference between commits exists but git log doesn't show changes

查看:322
本文介绍了提交之间存在差异,但git log不显示更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些奇怪的情况,并不能理解.

I have some curious situation and not undestand it.

当我使用git log -p -<n>时,看不到文件中存在的更改,但如果尝试git diff <prev>..<next> <file>,则存在差异并显示出来.为什么会这样呢?

When I use git log -p -<n> I don't see changes what exists in file, but If I try git diff <prev>..<next> <file> difference exists and shown. Why can it be?

Git diff返回Blob号index cd785c4..967453b 100644,我该怎么办?

Git diff returns blob numbers index cd785c4..967453b 100644, what I can do with that?

这些信息对我有帮助吗?

Can that information be helpful for me?

推荐答案

当我使用git log -p -<n>时,看不到文件中存在的更改,但如果尝试git diff <prev>..<next> <file>,则存在差异并显示出来.为什么会这样呢?

When I use git log -p -<n> I don't see changes what exists in file, but If I try git diff <prev>..<next> <file> difference exists and shown. Why can it be?

这意味着所涉及的提交是合并提交,即,至少具有两个父ID的提交.当git log -pgit show显示合并时,它们的默认设置是使用git的 combined diff 格式.

This means the commit in question is a merge commit, i.e., a commit with at least two parent IDs. When git log -p or git show is showing a merge, their default is to use git's combined diff format.

组合差异格式下的文档 部分,但我会引用:

请注意,组合差异仅列出从所有父级进行了修改的文件.

Note that combined diff lists only files which were modified from all parents.

(黑体字).例如,假设您将分支feature合并到分支develop中,并且在develop中文件README表示部分内容:

(boldface mine). Suppose, for instance, that you merge branch feature into branch develop, and that in develop, file README says, in part:

There will be a feature X soon.

假设在feature中,README表示:

Feature X is now supported.

feature合并到develop中时,文件README接受了更改—但是生成的READMEdevelop中的版本完全匹配.

When you merge feature into develop, the file README picks up the change—but the resulting README exactly matches the version in develop.

如果您现在git show合并提交(或它出现在git log -p中),则 combined diff 将合并中的README中的README进行比较父级(不同的是,当develop以前没有时,它具有现在受支持"的文本),然后将合并中的README second 父级中的README进行比较.第二次比较显示,由于合并使用了feature版本,因此没有变化,因此合并的diff 忽略了文件README .

If you now git show the merge commit (or it comes up in git log -p), the combined diff compares README in the merge against README in the first parent (it's different, it has the "now supported" text when develop didn't before), then compares README in the merge against README in the second parent. The second comparison shows no change since the merge picked up the feature version, so the combined diff omits file README.

当您找到合并的第一个父级ID,即合并之前是develop尖端的提交以及针对合并提交的git diff提交时,您将获得常规(非合并)差异,并且由于README获取了更改,因此您看到了更改.

When you find the first parent ID of the merge, i.e., the commit that was the tip of develop before the merge, and git diff that commit against the merge commit, you get a regular (non-combined) diff, and since README picked up the change, you see the change.

请注意,您可以使用-m选项告诉显示合并的内容(例如,git loggit show)对每个父对象显示一个差异,而不是单个组合差异. (对于典型的双亲合并,这会显示一次提交的两个差异.在内部,这些命令会生成一个伪额外的提交来执行此操作.您不必了解仅内部伪提交,但在某些情况下它会泄漏出去案例.

Note that you can use the -m option to tell things that show merges (git log and git show, for instance) to display one diff against each parent, rather than a single combined diff. (For typical two-parent merges, this shows two diffs against the one commit. Internally, these commands generate a fake extra commit to do this. You should not have to know about the internal-only fake commit, but it leaks out in some cases.)

Git diff返回Blob号index cd785c4..967453b 100644,我该怎么办?

请参见此答案.

这篇关于提交之间存在差异,但git log不显示更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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