Sub topic 10
Verifying the secret is gone
This chapter assumes you have already rotated the leaked credential and run git filter-repo on a fresh clone, using either --invert-paths or --replace-text. You should be comfortable with git log, git grep, and git rev-list. Verification comes before the force-push, because a push cannot be undone on the clones that fetch it.
Why you verify
A rewrite can succeed and still leave the secret behind. Common causes are a pattern that matched only one spelling of the string, a file that was renamed so an old path was missed, or a secret that also appears in a commit message. filter-repo reports success whenever it finishes. It does not report whether your rules covered everything.
Search the history for the string
Use two independent checks. They search in different ways, so one can catch what the other misses.
git log --all --oneline -S'AKIAEXAMPLEKEY12345'
git grep -I 'AKIAEXAMPLEKEY12345' $(git rev-list --all) || echo 'no matches'The first command is the pickaxe search. It lists every commit on any ref where the number of occurrences of the string changed. Empty output means no commit added or removed it.
The second command searches the file contents of every commit reachable from any ref. -I skips binary files. If nothing matches, git grep exits with a failure status and the echo prints no matches.
What the checks do not cover
Searching file contents does not search commit messages, author names, or tag annotations. Check them separately:
git log --all --format='%H %an %ae %s%n%b' | grep -F 'AKIAEXAMPLEKEY12345' || echo 'no matches in messages'
git for-each-ref --format='%(refname) %(contents)' | grep -F 'AKIAEXAMPLEKEY12345' || echo 'no matches in refs'If the first one finds a match, use --replace-message with the same expressions file and verify again.
Check that nothing else changed
Compare the rewritten repository with the original. The file list and the branch tips should look the same, apart from the removed or redacted content.
git branch -a
git tag
git log --all --oneline | wc -l
git diff --stat origin-backup/main mainThe last line assumes you kept a backup remote or a second clone under that name. Adapt the names to your setup. A large unexpected diff means your rules were broader than intended. Fix this before pushing.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Matches remain in old commits | The expressions file missed a spelling or encoding | Add a rule and run `filter-repo` again on a fresh clone |
| Match found only in a message | `--replace-text` does not rewrite messages | Run `--replace-message` |
| Match found in a tag | An annotated tag message contains the secret | Rewrite the tag message or delete and recreate the tag |
| Commit count changed unexpectedly | Commits became empty after a path removal and were pruned | Confirm this is expected |
Exercise
You ran git log --all --oneline -S'AKIAEXAMPLEKEY12345' after the rewrite and it printed nothing. Why should you still run git grep over git rev-list --all and check commit messages before force-pushing?
Show answer
The two searches work differently. -S only reports commits where the count of the string changed, and neither search looks at every place a secret can live. git grep over all commits checks file contents directly. Commit messages and tag annotations are not file contents, so they need their own search. Only after all of these come back empty is it safe to force-push.