Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log - find additions of a specified string

Tags:

git

How can I search through my git history for commits containing additions only of a specified string?

For example, how could I find all commits that contain additions of System.out.println or debugger.

I know of the -S argument that can be supplied to git log, but it includes all commits containing additions or subtractions of the specified string.

Is there a natural way to do it?

like image 863
Dan Fischer Avatar asked Dec 05 '14 03:12

Dan Fischer


People also ask

How do I search for a string in git log?

Simple! Drop the 'log' argument. This will show the commit ID and line number of all instances of your string. (The string can also be a regular expression, which is handy if you know regex, too.)

How do I search for a word in git log?

If you need to search words with space in between, git log --grep="my words" .

How do I see changes in git log?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

What is git log -- Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message.


1 Answers

Try the following one -

To search the commit log for the given string:

git log --all --grep='specific string'

To search the actual content of commits in the repository:

git grep 'specific string' $(git rev-list --all)

It will give all the instances of the given text, the containing file name, and the commit.

Hope this is what you want.

Updated

Check the following two links also -

git-grep

Search a git repo like a ninja

like image 177
royki Avatar answered Oct 05 '22 00:10

royki