如何获取git log -p以显示合并提交中的更改 [英] how to get git log -p to show changes in merge commits

查看:192
本文介绍了如何获取git log -p以显示合并提交中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个缺少函数定义的分支,但该函数仍在使用,导致崩溃.合并期间必须删除了功能定义.我已经完成了'git log -p'并搜索了函数定义,我可以看到它已被定义,但是以后找不到它被删除了.这使我相信'git log -p'不显示合并更改?如何获得此功能?

I have a branch with a function definition missing but the function is still being used causing a crash. The function definition must have been deleted during a merge. I have done 'git log -p' and searched for the function definition and I can see it being defined but couldn't find it being deleted later on. This leads me to believe that 'git log -p' doesn't show merge changes? How can I get this functionality?

推荐答案

这使我相信'git log -p'不显示合并更改?如何获得此功能?

This leads me to believe that 'git log -p' doesn't show merge changes? How can I get this functionality?

您是正确的:默认情况下,git log -p向您显示合并提交,但甚至没有尝试为它显示差异.

You are correct: by default, git log -p shows you the merge commit, but does not even attempt to show a diff for it.

作为 odradek写道在评论中,添加-c选项将使git log显示组合差异.您还可以使用--cc(注意,--cc用两个破折号,而-c用一个破折号)也显示组合的diff,或-m,它有效地分割合并diff目的,并显示每个父对象与该父对象之间的差异.

As odradek wrote in a comment, adding the -c option will make git log show combined diffs. You may also use --cc (note two dashes for --cc, vs one dash for -c) which also shows a combined diff, or -m, which effectively splits the merge for diff purposes, and shows one diff per parent, against that parent.

这三个选项可以与git show一起使用.但是,无论出于何种原因,git show 默认值为--cc,而git log默认为零.

These same three options can be used with git show. For whatever reason, though, git show defaults to --cc while git log defaults to nothing at all.

这三个选项之间的区别仅在进行某些合并时才清楚,要显示它们有些棘手.但是,我们可以说得很清楚:任何组合的差异仅显示不同于所有父项的文件. git show -c修剪显示的内容,以寻求帮助. (根据显示的内容,--cc格式可能会比-c修饰得更多.不过,我没有方便的示例.)

The difference between the three options is clear only with some merges, and it's a bit tricky to show them. We can, however, say one thing pretty clearly: any combined diff shows only files that differ from all parents. That is, both git show -c and git show --cc trim what's shown to try to be helpful. (The --cc form may trim more than -c, depending on what there is that can be shown. I do not have a handy example of this, though.)

例如,考虑在Git的Git存储库中提交3e5c63943d35be1804d302c0393affc4916c3dc3 .这是合并(与父级c13c783...20690b2...一起使用,如果我们运行两个 separate git diff命令,与 first 相比,我们可以看到它)父级,只有两个文件发生更改:

For example, consider commit 3e5c63943d35be1804d302c0393affc4916c3dc3 in the Git repository for Git. This is a merge (with parents c13c783... and 20690b2..., and if we run two separate git diff commands, we can see that, as compared to its first parent, only two files change:

$ git diff --name-status 3e5c639^1 3e5c639
M       builtin/remote.c
M       t/t5505-remote.sh

但与 second 父级相比,许多文件(包括相同的两个文件)发生了变化:

but as compared to its second parent, many files (including those same two) change:

$ git diff --name-status 3e5c639^2 3e5c639 | expand
M       .gitignore
M       .mailmap
M       Documentation/Makefile
A       Documentation/RelNotes/2.12.0.txt
M       Documentation/SubmittingPatches
A       Documentation/asciidoctor-extensions.rb
M       Documentation/blame-options.txt
M       Documentation/cat-texi.perl
M       Documentation/config.txt
M       Documentation/diff-config.txt
[snipped here - but the same two files do appear in the 339-entry list]

如果我对此执行git show --cc,那么我根本不会得到任何差异列表.如果在其上运行git show -c,则会得到builtin/remote.ct/t5505-remote.sh的差异列表.

If I run git show --cc on this, I get no diff listing at all; if I run git show -c on it, I get a diff listing for builtin/remote.c and for t/t5505-remote.sh.

如果我对此执行git show -m,则会获得两个单独的git diff列表. 两者都不是组合差异".首先是:

If I run git show -m on this, I get instead two separate git diff listings. Neither is a "combined diff". The first starts with:

commit 3e5c63943d35be1804d302c0393affc4916c3dc3 (from
 c13c783c9d3d7d3eff937b7bf3642d2a7fe32644)

,仅显示前两个文件.第二个开始于:

and shows just the first two files. The second starts with:

commit 3e5c63943d35be1804d302c0393affc4916c3dc3 (from
 20690b213975ad3e9b1bc851f434d818bd2d1de9)

并显示所有339个文件.

and shows all 339 files.

使用-m是真正的大锤子",但是您需要进行很多排序以完成许多任务.通常使用--cc-c就足够了.

Using -m is the Really Big Hammer, but you are left with a lot of sorting to do through a lot of pieces. Using --cc or -c is usually sufficient.

(在使用git log -p查找此类更改时,可能有其他帮助的方法是添加--full-history,以确保git log跟随 both 每次合并都分支.这仅当您通过添加-- <path>选项简化历史记录时才需要.)

(Something else that may help, when looking for this sort of change with git log -p, is to add --full-history to make sure that git log follows both branches down each merge. This is only required if you are doing history simplification by adding -- <path> options.)

这篇关于如何获取git log -p以显示合并提交中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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