如何显示差异在合并提交中所做的更改? [英] How to show diff of changes made in a merge commit?

查看:58
本文介绍了如何显示差异在合并提交中所做的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写一堆代码时,我没有意识到自己正处于合并的中间.现在git log -p不会向我显示此更改的差异(该更改已作为合并提交自动提交).

I didn't realize I was in the middle of a merge when I wrote a bunch of code. Now git log -p will not show me the diff of this change (which got auto-committed as a merge commit).

如何将其显示在日志比较历史记录中?

How can I get it to show up in my log diff history?

推荐答案

Git并未向您显示与-p合并的补丁,这令人有些失望.部分原因是-p生成的补丁是统一的diff,它是基于一个基础版本和一个目标修订版创建的.合并有两个基础,因此统一的差异不能代表需要进行的更改.

It's a bit disappointing that Git doesn't show you a patch for merges with -p. Part of the reason is that the patch produced by -p is a unified diff, and it's created from one base and one target revision. A merge has two bases, so a unified diff isn't representative of the change that needs to be made.

因此,有两种获取所需内容的方法. git log -p -c将在合并提交中向您显示N个差异,其中N是合并父级的数量.或者,您可以使用git log -p --cc并查看diff的更紧凑形式.它看起来很像一个统一的diff,但是可以处理合并具有多个父对象的事实. FWIW,--cc代表紧凑组合".如果对有问题的提交运行git show SHA1,则会看到紧凑的组合输出.

So there are two ways to get what you want. git log -p -c will show you N diffs in a merge commit, where N is the number of merge parents. Or, you can use git log -p --cc and see a more compacted form of the diff. It looks a lot like a unified diff, but can handle the fact that merges have multiple parents. FWIW, --cc stands for "compact combined". Compact combined output is what you would see if you ran git show SHA1 for the commit in question.

另一个小注意事项:如果在合并提交中未进行任何编辑,则在git log -p --cc输出中将看不到差异.另外,默认情况下,当前没有办法使差异显示合并提交.最好的办法是,如果您需要简短而令人难忘的内容,请使用别名.

One more small note: if there were no edits where made in a merge commit, then you will not see a diff in the git log -p --cc output. Also, there's current no way to make a diff show up merge commits by default. You're best bet is to use an alias if you need something short and memorable.

这篇关于如何显示差异在合并提交中所做的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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