Learning center

Is a secret finding resolved once the latest commit deletes the secret?

No: the commit that added the secret still holds it in every clone and fork, so the finding closes when the credential is revoked. Rewriting history is a second, optional step that cannot reach copies other people already have. The one case where deletion alone is enough is a value that was never a working credential, and that needs its own evidence.

Where the value still lives#

A Git commit stores a snapshot. Deleting a line in commit B leaves commit A, its tree and its blob exactly as they were, and every repository that fetched A has its own copy. A scanner that reads only the working tree reports nothing after the delete; one that reads history keeps the finding. gitleaks has both modes, and its README at v8.21.2 says the git command "uses the git log -p command to scan patches", while dir "lets you scan directories and files."

This constructed repository has a bare origin.git, a developer clone, a teammate's clone and a mirror standing in for a fork. The developer committed a token shaped like a GitHub classic personal access token (ghp_ plus 36 characters, which the gitleaks github-pat rule matches; generated locally and never issued), pushed it, then replaced it with an environment variable read and pushed again. The teammate and the fork fetched between the two pushes. With gitleaks built from tag v8.21.2 and Git 2.43.0:

$ gitleaks dir --no-banner .
INF no leaks found
$ gitleaks git --no-banner --no-color -v --redact=85 .
Finding:     ghp_ja...
Secret:      ghp_ja...
RuleID:      github-pat
Entropy:     4.921928
File:        deploy/sync.py
Line:        3
Commit:      3c791529acb55e4ae54906c16896dfbe8da0b3ac
Date:        2026-11-25T08:37:23Z
INF 2 commits scanned.
WRN leaks found: 1

The two runs disagree because they read different things. A finding from a history scan names a commit; check whether that commit is reachable before you check the file at HEAD.

Show every commit and copy that holds it#

git log -S lists the commits that change the number of occurrences of a string, which finds both the commit that added the value and the one that removed it:

$ git log -p -S "$TOKEN" --format='%h %s'
f11ceb8 Read token from environment
-GH_TOKEN = "ghp_..."
+GH_TOKEN = os.environ["GH_TOKEN"]
3c79152 Add issue sync
+GH_TOKEN = "ghp_..."
+                         headers={"Authorization": f"Bearer {GH_TOKEN}"}, json={"title": title})

(Diff context trimmed; the token is shortened in every listing here.) The second commit shows how the value was used: as a bearer token against the GitHub API, which makes it a credential rather than a string that looks like one. Walking every reachable commit shows which ones hold it:

$ for c in $(git rev-list --all); do echo "$(git rev-parse --short $c) $(git grep -c "$TOKEN" $c -- || echo 'not present')"; done
f11ceb8 not present
3c79152 3c791529...:deploy/sync.py:1

Then check the copies. The teammate's clone and the fork still carry the token in their checked-out branch, because they never pulled the deletion:

$ git -C teammate grep -c "$TOKEN"
deploy/sync.py:1
$ git -C fork.git grep -c "$TOKEN" main
main:deploy/sync.py:1

Anyone who can read the repository could have fetched the token at any time after the first push: the deletion commit sits on top of the commit that holds it, so every later clone gets that commit too. Deleting the line on main changed nothing for those copies.

Revoke first, then decide about history#

GitHub's documentation puts the order plainly: "if the sensitive data you need to remove is a secret (e.g. password/token/credential), as is often the case, then as a first step you need to revoke and/or rotate that secret. Once the secret is revoked or rotated, it can no longer be used for access, and that may be sufficient to solve your problem." (Removing sensitive data from a repository, github/docs at bd60abd)

Revocation is the only step that acts on every copy at once. After it, collect the provider's record of what the credential did between the first push and the revocation. That record, not the Git history, says whether anything else needs a response.

Rewriting history is worth doing when the repository is public or widely cloned and you want future clones clean, but it has limits you can see in the fixture. git-filter-repo 2.47.0 replaced the token across history, and the rewritten branches were force-pushed to origin.git:

$ git-filter-repo --sensitive-data-removal --replace-text ../replace.txt   # output trimmed
$ git push --force --mirror origin
$ git -C origin.git log --oneline --all -S "$TOKEN"
$ git clone --no-local origin.git fresh && git -C fresh cat-file -t 3c79152
fatal: Not a valid object name 3c79152
$ git -C origin.git show 3c79152:deploy/sync.py | grep '^GH_TOKEN'
GH_TOKEN = "ghp_..."
$ git -C fork.git log --oneline -S "$TOKEN"
3c79152 Add issue sync

A new clone is clean, but the server repository still holds the old commit, readable by its SHA, until its objects are pruned, and the fork and the teammate's clone are untouched. The GitHub page lists the same places: after a rewrite and force push, the commits "may still be accessible elsewhere", in clones and forks, by SHA-1 in cached views on GitHub, and through pull requests that reference them. It adds that GitHub Support "will only assist in the removal of sensitive data in cases where we determine that the risk can't be mitigated by rotating affected credentials."

When deleting the value was enough#

The decision flips if the value was never a working credential. Evidence for that has to come from the issuer, not from the value's shape, because a format match only says what the value claims to be.

In a second constructed repository, a developer committed a JWT as a test fixture and removed it in the next commit. gitleaks flags it in history with rule jwt and commit 2bae38f. Decoding the header and claims without verifying them shows where it came from:

$ python3 jwt_claims.py "$(git show 2bae38f:tests/fixtures/admin_session.txt)"
header: {'alg': 'HS256', 'typ': 'JWT'}
claims: {'iss': 'http://localhost:9000/test-idp', 'sub': 'admin@example.test', 'role': 'admin', 'iat': 1767225600, 'exp': 1767229200}

The issuer is a local test identity provider, and the token verifies with the key in tests/mint.py. The question is whether production would accept it, so run production's own verification code against it. Here app/auth.py accepts only RS256 tokens from https://auth.example.com; with PyJWT 2.15.1 and a locally generated stand-in public key:

$ python3 prodcheck.py "$TOKEN"
InvalidAlgorithmError: The specified alg value is not allowed

The verifier rejects the algorithm before it reaches the signature or the issuer, so no key held by production could have accepted this token. Record the issuer, the verifier's rejection and the test key's location with the dismissal. That evidence covers this token only: if the same test key or test issuer were also configured in a deployed environment, the token would be a credential there.

Decide from the issuer and the copies#

What the finding saysEvidence to collectDecision
Secret in a history commit, absent at HEADgit log -p -S for the adding commit and how the value was usedTreat as exposed: revoke or rotate with the provider
Same, repository has forks or other clonesFork and clone list; whether the repository was readable by others after the first pushRevoke; rewriting cannot reach those copies
Credential already revokedProvider record of use between first push and revocationClose the finding with the revocation and that record
History rewrite requestedgit-filter-repo run, force-push, objects still reachable by SHADo it after revocation, for future clones only
Value minted by a test issuer or test keyDecoded issuer, production verifier's result, where the key livesDismiss if production rejects it and the key exists nowhere deployed

Before a credential reaches history at all, push protection can stop it; the guide to push protection bypasses covers what to do when someone pushes past it. For a flagged value whose nature is unclear, the high-entropy string guide shows how to tell a credential from a hash or an identifier.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading