よしだです

プログラミングの勉強してます

githubのcommit履歴を消したい

githubにpushしてから、パスワードとかベタ貼りのファイルをpushしてしまったことに気づいたので慌ててcommit履歴を消しました。


手順

①消したいファイルをコピーしてバックアップを取る
cp file_path コピー先のpath
②commit履歴を消す
git filter-branch -f --index-filter 'git rm --ignore-unmatch ファイルのpath' HEAD
③バックアップしたファイルを戻す
mv file_path 移動先のpath
githubにpush
git push -f origin master

これでcommit履歴が消えてます。