gitversion-control

Filter git log to find deleted file by some user


Long time ago, there was a spike that I did to try something, and then I removed it.

I don't remember when I removed it (more than a year or maybe two years ago), but it was in our codebase for two or three months.

The spike was a code to read "pfx" files, and include unit tests.

I want to see if I can retrieve the code.

All what I know, is the code that I removed

  1. deleted a file with extensions "pfx"
  2. was under our "test" folder
  3. and was removed by me.

Is there a way to find that code


Solution

  • You could use the git log command with a glob pattern to narrow down the list of commits that affected pfx files under the test folder.

    To help you to identify the test file, you could use the following options:

    # searching from the main line of development 
    git log --diff-filter=D --author=<author-name> --name-only master -- test/**/*.pfx
    

    Once you obtain the list of commits, you can restore the file with git checkout from the commit responsible of its deletion.

    git checkout <commit-id> -- <file-path>