At first, I was using the following command:

Method 1: using git log file path filter

We can use the below command to search git log for commits that touches an specific file

git log --all -- deleted_file.example --oneline

Obviously, instead of deleted_file.example we will have to write the exact name/path of the file that we are looking for. So, if we are searching for main.py it will be git log --all -- main.py

This will list all the commits that touched the file but, there is a better alternative in newer version of gits:

Method 2: using diff-filter

The below command filters commits that deleted file using diff-filter from git log

git log --diff-filter=D --  deleted_file.example

It takes advantage of the flag diff-filter. The cool thing about diff-filter is we can also use it to find the commit that first added the file! example:

git log --diff-filter=A --  file.example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: