List all git commits that delete any file
Asked Answered
S

2

7

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.

Safranine answered 27/6, 2022 at 19:51 Comment(0)
O
4

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

Opiumism answered 27/6, 2022 at 19:54 Comment(1)
What about starting without any history to open source it clean and fresh ?Paintbrush
A
2

a side note :

if you know what to look for in the diffs -- for example, if you know you should look for files which contain strings like AWS_SECRET_KEY=... or API_KEY=..., or if you know the value of the secrets that could appear in said files -- you can use the -G option :

# will list all commits where the string 'AWS_SECRET_KEY' appears in the diff :
git log --name-status -G "AWS_SECRET_KEY" --all
Atone answered 28/6, 2022 at 3:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.