Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show all commits whose diff contain specific string

Tags:

As the title says, I want to find every commit whose diff contains specific string.

At the moment, I use

git log -p 'filename' 

Which shows less like interface of every diff, where I search for the string. Then I backtrace to find the actual commit msg.

Simple alternative might be to pipe git log -p into grep, but I can not find the commit id or message that way.

like image 788
bbaja42 Avatar asked Aug 21 '13 17:08

bbaja42


People also ask

How can I see diff commit?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

Which command shows the difference between commits?

The git diff command displays the differences between files in two commits or between a commit and your current repository.

How do you find all the commits made on a branch?

Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

How do I search for a string in git log?

Simply run git log with the -L option, and it will show you the history of a function or line of code in your codebase.


1 Answers

git log -p -S'string' 

can be used to search for commits that add or remove a string. It doesn't behave exactly the same, because it only matches commits that actually add or remove an instance of the pattern, and not (for instance) commits where it occurs in the diff context. But maybe that's good enough for you.

like image 95
David Avatar answered Sep 22 '22 01:09

David