Search all of Git history for a string?

1.7K    Asked by DylanPowell in Tableau , Asked on Jul 4, 2021

I have a codebase which I want to push to GitHub as open source. In this git-controlled source tree, I have certain configuration files which contain passwords. I made sure not to track this file and I also added it to the .gitignore file. However, I want to be absolutely positive that no sensitive information is going to be pushed, perhaps if something slipped in-between commits or something. I doubt I was careless enough to do this, but I want to be positive.

Is there a way to "grep" all of the git? How to search git history? Is it possible to get every version of every file that ever existed? I guess if there is a command that dumps the diff file for every commit, that might work?

Answered by Donna Chapman

To search git history, you can use:

git grep "the magic string" `git show-ref --heads` If the string exists in your repo, anywhere, you'll get something like this:

***c5cd1d8:path/to/file.js:let a = "the magic string" Once you have that data, it's as easy as finding the branch!

git branch --contains ***c5cd1d8.



Your Answer

Interviews

Parent Categories