how can I use git log to use parent #1 to generate the patch

Viewed 90

I can see the left hand lane of my git history like this:

git log origin/master --pretty=oneline --first-parent --decorate=no

the way my project is set-up, those are the only important changes most of the time.

However, when searching the patches with -G, I would like to search the difference between the commit, and its parent #1, so that every change that has happened in the project is covered by the search.

git log origin/master --pretty=oneline --first-parent --decorate=no -G keyword

The reason is that the tree looks like this

enter image description here

and I want to consider that whole trapezoid as a single action for some purposes. In the list generated by the above git log, it is shown as a single command, but I have no way of then searching the history in that format so that I can tell immediately in which git group that happened.

It would also be great if whatever options can do this could work for gitk so that when I go

gitk origin/master --first-parent

and make it appear as a single commit

enter image description here

I could click on it and see the diff generated by

git diff [merge commit]:[merge commit]^

The git documentation mentioned environment variables GIT_EXTERNAL_DIFF and GIT_DIFF_OPTS that sound like they might be what I am looking for, but I can't really find any examples.

1 Answers

Add the -m flag to the command you already have:

git log -m --pretty=oneline --first-parent --decorate=no -G keyword origin/master

(I moved the starting point to the end of the options, although for Git, you can put it wherever you like as long as it is not after a double hyphen --).

The -m option—think of it as short for merge—makes git log treat a merge commit as a series of multiple separate commits, each with the same child commit but each with a single parent. When combining this with --first-parent, it treats the merge commit as if it were just an ordinary non-merge commit with the first parent as its only parent. In either case, you do get a diff, which -G can then search.

(Unfortunately, this does not work with gitk, which doesn't use git log directly. It runs its own git rev-list internally and then does everything else on its own.)

Related