Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search git history for a change in a merge commit

Tags:

To search for a string that has been added/removed in git history I can do

git log -S'some text'

This works great except that it doesn't search through merge commits. How do I get the command to include merge commits in the search?

like image 858
opsb Avatar asked Oct 31 '09 18:10

opsb


People also ask

How do I see changes in a merge commit?

It shows all the changes made to the merged branch as a result of the merge. Show activity on this post. git show -c c0f501 will display a combined diff from commit c0f501 to both of its parents, as printed by git diff during a merge. This gives a better overview than git show -m .

Does git merge change history?

A merge takes two or more branches, and creates a commit that interleaves the changes in all parents (resolving conflicts, as needed; the user has to decide how). git does not change history by itself.

Which command is used to display merge history in git?

I'll start by showing how the default “chronological” order of git log can mislead you when the history contains merge commits. Then I'll show how you can visualize Git merge history using git log --graph , and how to see the “true” history of a single branch using --first-parent .


2 Answers

it appears that the -m flag gives me the desired result

git log -m -S'some text'

I found this on another site, if someone could point me in the direction of a man page that includes this flag that would be great. This one doesn't include it http://ftp.kernel.org/pub/software/scm/git/docs/git-log.html

like image 63
opsb Avatar answered Sep 28 '22 09:09

opsb


Since some Git commands are built on top of other ("plumbing") commands they often inherit options from other commands. I agree that it's annoying not to see those documented in the man pages or in the --help output. In this case, the git-log help states:

The command takes options applicable to the git-rev-list command to control what is shown and how, and options applicable to the git-diff-* commands to control how the changes each commit introduces are shown.

In this case, you'll find the -m option under git-diff-tree:

...
-m
    By default, git-diff-tree --stdin does not show differences 
    for merge commits. With this flag, it shows differences to 
    that commit from all of its parents. See also -c.
...
like image 32
Pat Notz Avatar answered Sep 28 '22 09:09

Pat Notz