Skip to content

Commit 88d9d45

Browse files
Petr Baudisgitster
authored andcommitted
git log -p -m: document -m and honor --first-parent
git log -p -m is used to show one merge entry per parent, with an appropriate diff; this can be useful when examining histories where full set of changes introduced by a merged branch is interesting, not only the conflicts. This patch properly documents the -m switch, which has so far been mentioned only as a fairly special diff-tree flag. It also makes the code show full patch entry only for the first parent when --first-parent is used. Thus: git log -p -m --first-parent will show the history from the "main branch perspective", while also including full diff of changes introduced by other merged in branches. Signed-off-by: Petr Baudis <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8051a03 commit 88d9d45

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

Documentation/diff-generate-patch.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ combined diff format
5656

5757
"git-diff-tree", "git-diff-files" and "git-diff" can take '-c' or
5858
'--cc' option to produce 'combined diff'. For showing a merge commit
59-
with "git log -p", this is the default format.
59+
with "git log -p", this is the default format; you can force showing
60+
full diff with the '-m' option.
6061
A 'combined diff' format looks like this:
6162

6263
------------

Documentation/git-log.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ git log master --not --remotes=*/master::
118118
Shows all commits that are in local master but not in any remote
119119
repository master branches.
120120

121+
git log -p -m --first-parent::
122+
123+
Shows the history including change diffs, but only from the
124+
"main branch" perspective, skipping commits that come from merged
125+
branches, and showing full diffs of changes introduced by the merges.
126+
This makes sense only when following a strict policy of merging all
127+
topic branches when staying on a single integration branch.
128+
129+
121130
Discussion
122131
----------
123132

Documentation/rev-list-options.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ options may be given. See linkgit:git-diff-files[1] for more options.
108108

109109
-c::
110110

111-
This flag changes the way a merge commit is displayed. It shows
112-
the differences from each of the parents to the merge result
111+
With this option, diff output for a merge commit
112+
shows the differences from each of the parents to the merge result
113113
simultaneously instead of showing pairwise diff between a parent
114114
and the result one at a time. Furthermore, it lists only files
115115
which were modified from all parents.
@@ -121,6 +121,15 @@ options may be given. See linkgit:git-diff-files[1] for more options.
121121
the parents have only two variants and the merge result picks
122122
one of them without modification.
123123

124+
-m::
125+
126+
This flag makes the merge commits show the full diff like
127+
regular commits; for each merge parent, a separate log entry
128+
and diff is generated. An exception is that only diff against
129+
the first parent is shown when '--first-parent' option is given;
130+
in that case, the output represents the changes the merge
131+
brought _into_ the then-current branch.
132+
124133
-r::
125134

126135
Show recursive diffs.

log-tree.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,16 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
514514
return 0;
515515
else if (opt->combine_merges)
516516
return do_diff_combined(opt, commit);
517+
else if (opt->first_parent_only) {
518+
/*
519+
* Generate merge log entry only for the first
520+
* parent, showing summary diff of the others
521+
* we merged _in_.
522+
*/
523+
diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt);
524+
log_tree_diff_flush(opt);
525+
return !opt->loginfo;
526+
}
517527

518528
/* If we show individual diffs, show the parent info */
519529
log->parent = parents->item;

0 commit comments

Comments
 (0)