Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find last commit in Git repo that contains a certain string pattern [duplicate]

Tags:

git

grep

awk

I want to go back in time to the last commit which contained code such as, "ThisClass(object):". That code was subsequently removed from the project in a later commit.

I thought about using git bisect + grep/awk-ing. I've also heard that git grep may allow you to do this sort of thing, though I can't figure out the right command in the man pages.

Any thoughts?

like image 860
Ben Avatar asked May 03 '12 17:05

Ben


People also ask

What is grep in git?

Git ships with a command called grep that allows you to easily search through any committed tree, the working directory, or even the index for a string or regular expression.

How do you see the changes in a commit?

Looking up changes for a specific commit If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .


1 Answers

Use the -S (search) argument to git log:

git log -S 'ThisClass(object):'
like image 62
Ethan Brown Avatar answered Sep 27 '22 20:09

Ethan Brown