Question
How can I list all the commits that delete any file in the repo? (not a specific file, but all the commits that delete anything).
Context
We have a multiple-years-old repo and we plan to release the project as open-source.
We want to check that no credentials are filtered into the public.
For the tracked files we can easily see what is in there and if in the past there was anything secret.
But we want to see if "at any time, there was any file that could potentially disclose secrets."
We want just to list all the files that were tracked and later deleted, to review those portions of the history.
CodePudding user response:
Listing all the deleted files in all of git history can be done by combining git log
with --diff-filter
. The log gives you lots of options to show different bits of information about the commit that happened at that point. It's even possible to get a completely clean list of files that are in your git history but have been deleted.
These various commands will show all files that were ever deleted on your current branch:
# This one includes the date, commit hash, and Author
git log --diff-filter D
# this one could be a git alias, but includes empty lines
git log --diff-filter D --pretty="format:" --name-only
# this one has the empty lines cleaned up
git log --diff-filter D --pretty="format:" --name-only | sed '/^$/d'
The git reflog
command can be super powerful in finding lost files, as it only cares about git operations, not just the current branch. It will search accross all branches for deleted files and report them.
# This one includes the commit hash, branch, tag, and commit message
git reflog --diff-filter D
# You might want to at least add the filename
git reflog --diff-filter D --name-only
# this one could be a git alias, but includes empty lines
git reflog --diff-filter D --pretty="format:" --name-only
# this one has the empty lines cleaned up
git reflog --diff-filter D --pretty="format:" --name-only | sed '/^$/d'
CodePudding user response:
git log --diff-filter=D --summary
See Find and restore a deleted file in a Git repository
If you don't want all the information about which commit they were removed in, you can just add a grep delete in there.
git log --diff-filter=D --summary | grep delete