Jeff Lembeck learns a code or two

Serious code business!

WHO DELETED THAT FILE?

So, there you are, working on a huge project that has 50+ devs on it because #enterprise and you realize that some files are missing. How long have they been missing? WHO DELETED THAT? WHY (most important question here, really)?Crap.

TO THE GIT-MOBILE

$ git log --diff-filter=D --summary

That will give you every commit where a file was deleted, but you don't have time to look through these, and you remember where these files were, right? So you go to use grep, that's a handy thing.

$ git log --diff-filter=D --summary | grep DeletedFile.js

Huh, but it gives you a print out that is useless. Let's see if we can't make our initial output a little better.

$ git log --diff-filter=D --pretty=format:"%h: %ae %an" --name-only

Well now we have all of our deletion commits coming out as

CommitHash: AuthorEmail AuthorName

file deleted

file deleted

...

We're closer, but not quite there.

Let's go back to using some grep; did you know that grep can also search backwards from your line? Oh, you didn't? We hereeee we go

$ git log --diff-filter=D --pretty=format:"%h: %ae %an" --name-only | grep -B 1 DeletedFile.js

Output looks like this now

CommitHash: AuthorEmail AuthorName

file deleted

For your specific file!

Woo!

Now, before you go asking questions, it's probably best to run a git show on that commit hash.

Back to Blog