6

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?

1 Answer 1

6

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> 
Sign up to request clarification or add additional context in comments.

1 Comment

Actually, "git blame --reverse" won't tell you who deleted the lines directly. It tells you the last revision in which the lines existed. So how do you find the guilty revision that actually removed the line? This is how I figured out how to do it: take revision LR from the git blame --reverse output, then do this: git log --reverse --ancestry-path $LR..HEAD <file>, and the first entry is a candidate, call it C. Then use git show $C to check, and if it's not what you're looking for, start again with git blame, replacing R with C.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.