Reputation: 15375
I have a private git repo where I have a keyword like abcde
I previously wrote down in 1 of the files that may or may not still be in the repo today. Is there a simple way to search all the files of all previous commits for my keyword abcde
?
I'm thinking I need to write a script to search every current file but if it's not present just start git reset --hard previousCommit
until it reaches the very 1st commit.
Upvotes: 0
Views: 613
Reputation: 113
You would have to iterate two lines of code N times:
(if you have N commits for example)
for VARIABLE in 1 .. N
do
git checkout HEAD^
grep keyword *
done
So, in your case, you can copy and paste the following code into git bash:
for VARIABLE in 1 .. 2500
do
git checkout HEAD^
grep abcde *
done
The iteration stops when the next commit no more presents what you are looking for.
Once this is done, you can finally see what the SHA identifier of the oldest commit is that has the word you are looking for. And then possibly apply the "reset --hard"
I hope I have been helpful. 🙂
Upvotes: 0
Reputation: 534885
You are probably looking for
git log -G mykeyword
With a single git log command, you can search for the commit that introduces any given text.
Upvotes: 1