Step by step: rotate the key first, stop tracking the file, check and rewrite history, and add a pre-commit hook that refuses the path.手順:先に鍵を失効、追跡を外す、履歴を確かめて書き換える、そのパスを断る pre-commit フックを置く。
If the commit was pushed, treat the secret as read by others. Revoke it at its issuer and create a new one. Cleaning Git does not un-leak a key.push 済みなら、その秘密は他人に読まれたものとして扱います。発行元で失効し、新しく作り直します。Git を掃除しても、漏れた鍵は元に戻りません。
--cached removes the file from the index only. Then add the ignore lines and commit.--cached は索引から外すだけで、手元のファイルは消えません。続けて除外の行を足して commit します。
git rm --cached --ignore-unmatch .claude/settings.local.json .env
printf '.env\n.env.*\n.claude/settings.local.json\n' >> .gitignore
git add .gitignore && git commit -m "stop tracking local settings"
If this prints commits, the old content is still in this repository's history, and in any clone or fork made since. It only looks at the history you have locally.これで commit が出るなら、古い中身はこのリポジトリの履歴に残っており、その後に作られた複製やフォークにも残っています。見ているのは、手元にある履歴だけです。
git log --all --oneline -- .claude/settings.local.json .env
git filter-repo is a separate tool that must be installed. Agree a time with collaborators first. Run it on a fresh clone; it removes the origin remote on purpose, so add it back, force-push every branch and tag, then run step 3 again to confirm. Everyone else has to clone again. Forks, existing clones and cached pull-request views are not changed by this, which is why step 1 comes first.git filter-repo は別に入れる道具です。先に共同作業者と時間を決めます。新しく clone した場所で実行します。この道具は origin をあえて外すので、付け直してから、すべてのブランチとタグを強制 push し、手順3をもう一度実行して確かめます。他の人は clone し直しです。フォーク・既存の複製・プルリクエストの保存表示は、これでは変わりません。だから手順1が先です。
git filter-repo --invert-paths --path .env --path .claude/settings.local.json
git remote add origin <your repository address>
git push --force --all && git push --force --tags
An ignore line can be overridden with git add -f. A pre-commit hook on this clone refuses the path on an ordinary commit. It can still be skipped on purpose with the commit option that skips hooks, and it is not copied to other clones, so back it with the same check in CI.除外の行は git add -f で越えられます。この複製に置いた pre-commit フックは、ふつうの commit でそのパスを断ります。ただし、フックを飛ばす commit の指定を意図して使えば越えられ、他の複製には写りません。同じ検査を CI にも置いてください。
#!/bin/bash
# .git/hooks/pre-commit — refuse these paths on an ordinary commit, even after "git add -f"
while IFS= read -r -d "" f; do
case "$f" in
.env|.env.*|*/.env|*/.env.*|.claude/settings.local.json|*/.claude/settings.local.json|*.pem)
echo "refused: $f must not be committed"; exit 1;;
esac
done < <(git diff --cached --name-only -z)
No. The old commit still holds it. Anyone with a clone, a fork or the commit address can read it. Rotate the key.消えません。古い commit に残ります。複製・フォーク・その commit の場所を知る人は読めます。鍵を失効してください。
It prevents accidents, not intent or tooling: git add -f and some tools bypass it. A pre-commit hook refuses the path on ordinary commits in that clone; a CI check covers the rest.うっかりは防げますが、git add -f や一部の道具は越えます。pre-commit フックは、その複製でのふつうの commit でそのパスを断ります。残りは CI の検査で補います。
The free scanner on this site lists supported patterns in a folder inside your browser; the files are not uploaded. A result without findings is not proof that nothing is there.このサイトの無料スキャナーが、ブラウザの中でフォルダ内の対応済みの型を一覧にします。ファイルは送信されません。検出なしは、何も無いことの証明ではありません。
Written with AI assistance (Claude). The figures are measured or computed as named on the page. The commands are examples: read them and adapt them to your repository before running. Product links lead to our own paid kits.AI(Claude)の補助を使って書いています。数字は、ページに記したとおりの実測値か計算値です。コマンドは例です。実行の前に読み、自分のリポジトリに合わせて直してください。商品のリンク先は、当方の有料のキットです。