Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out when some portion of a file was deleted in git?

Tags:

git

I just found out, that one of my test files is missing about 20 lines on the top.

I've been recently trying to master VIM, so I guess I somehow managed to delete those lines without me even noticing, and then commiting it into the repository.

Now the question is, what's the best way to find out when this happened? How can I tell when something was deleted?

like image 504
Jakub Arnold Avatar asked Dec 20 '11 11:12

Jakub Arnold


Video Answer


1 Answers

Find a revision R where those line existed, then use

git blame --reverse $R..HEAD <file>

This will show you who deleted them.

If you can't find such a revision, but you remember a string (say 'test_database') contained in the missing lines, you can use the pickaxe feature to search for commits involving that string:

git log -Stest_database <file>
like image 59
Paolo Capriotti Avatar answered Sep 30 '22 19:09

Paolo Capriotti