If you accidentally perform a commit with sensitive data, I found this recovery approach to be fairly straightforward.
- (Optional) If you want to keep the file but not the changes, save off the file that has the secret. The command below will completely remove the file.
- Install Python if not already installed
- From command line
pip install git-filter-repo
- Clone a fresh copy of the repository
- Run the command to remove the file
git filter-repo --path path/to/your_file_with_secret --invert-paths
- Add the remote origin if not set (
git remote-v
to check), and then check it was set
git remote add origin https://github.com/davehague/timeline.git
git remote -v
- Force push
git push --set-upstream origin main --force
- Re-clone your repository. Don't forget to move your non-committed files over before deleting the old one (
.env
) - (Optional) Add the file back in, make sure not to include the secret!