Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find 'lost' code with a constant in Git

Once upon a time, one bad guy had deleted a constant from the source code managed through our Git repository.

Nobody has noticed this for a loooong time.... until now.

Yet I want to figure out in which commit this constant is gone, and who the bad guy is.

I only know the constant's name was FOOBAR.

Is there some better approach as git blame --reverse?

like image 372
astropanic Avatar asked Nov 22 '10 16:11

astropanic


People also ask

How do you find a commit which broke something after a merge operation?

To track down a broken commit, git gives us a very handy tool called git bisect . Git bisect does a binary search to find the broken commit.

Which command is used to find the commit that introduced a bug?

The git bisect command is used to discover the commit that has introduced a bug in the code. It helps track down the commit where the code works and the commit where it does not, hence, tracking down the commit that introduced the bug into the code.


1 Answers

This will list all commits that added or removed the string FOOBAR from any file:

git log --all -p -SFOOBAR
like image 137
cdhowie Avatar answered Oct 09 '22 06:10

cdhowie