git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: log -p hides changes in merge commit

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 6, 2011, 21:04 UTC
Message-ID
<20110106210438.GB15090@burratino>
In-Reply-To
<4D262B05.2060306@cfl.rr.com>
Phillip Susi wrote:
Show 7 quoted lines
> What I would like to do is be able to review a merge to sign off on it.
>  While the full diff against the left parent would be a large and
> unhelpful amalgamation of the changes in the merged branch, any
> additional changes made during the commit should not be hidden.  This
> allows someone performing the merge to effectively sneak in unintended
> changes.  I would expect any such changes to be shown by log -p, but
> this only seems to happen if you add -c.

To be more precise, here is what -c and --cc do. Consider the following history (time flowing left to right):

    -- [topic]
   /
 B --- [master]
>From the master branch, I merge topic.  (1) If I am lucky, the changes

from B to topic and B to master touch entirely different sections of code (though perhaps within the same files), so one could just apply the two diffs in succession to make a merge automatically. (2) Almost as good is the case when they touch code a couple of lines apart --- "git merge" still figures it out automatically. (3) Less nice is the case when they touch the same line, say --- but even here the correct merge can be obvious. (4) Worst of all is when the changes semantically conflict but syntactically do not:

	$ git merge topic
	$ make test;	# fails!
	$ ... hack hack hack ...
	$ git commit --amend
   -- o [topic] ------
  /                   \
 B -- o --------------- [master]

In case (1), -c will show a "combined diff" for files where master does not match either the old master or topic. --cc, on the other hand, will correctly suppress these uninteresting diffs.

In case (2), -c will show a noisy "combined diff" as before. --cc will show a combined diff when the changes from both parents touch nearby code, even if it merged trivially.

In case (3), -c and --cc will show the semantically boring but syntactically interesting merge.

Case (4) is underspecified. So let's give a more precise example: the old master and topic tried to fix the same bug in two incompatible ways. When merging, I decide I like the topic's way better, so I resolve conflicts in favor of the topic. Hopefully all unrelated changes on master were preserved!

In this case, -c and --cc will very likely show nothing at all. Each file matches one of the two parents (old master or topic) so there is no easy way to distinguish the case from (0) or (1).

By now it should be clear how to get the diff you are looking for. One makes a test merge, perhaps using the iffy "resolve in favor of one side or the other" feature to save time on conflicts:

	git checkout oldmaster^0
	git merge topic
	git reset --merge ORIG_HEAD; # meh, too many conflicts
	git merge -Xours topic
and then makes a diff.
	git diff master

Hope that helps, Jonathan

Previous: Phillip SusiNext: Phillip Susi
Message 4 of 6 in “log -p hides changes in merge commit”
  1. Phillip SusiJan 6, 2011
  2. Junio C HamanoJan 6, 2011
  3. Phillip SusiJan 6, 2011
  4. Jonathan NiederJan 6, 2011
  5. Phillip SusiJan 7, 2011
  6. Junio C HamanoJan 7, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.