I checked in (into github) some sensitive files by mistake. To remediate this, I followed the instructions here and ran the commands:
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch settings.json" --prune-empty --tag-name-filter cat -- --all
echo "settings.json" >> .gitignore
git add .gitignore
git commit -m "Add settings.json to .gitignore"
git push origin --force --all
git push origin --force --tags
git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
I can however go to my commit history to see the deleted file.
To fix this issue, how can I delete the file from github commit history?
Browse to the directory in your repository that you want to delete. In the top-right corner, click , then click Delete directory. Review the files you will delete. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
Try instead to use the best practice is to use the new tool git filter-repo
which replaces BFG and git filter-branch
.
Note: if you get the following error message when running the above-mentioned commands:
Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`
it means you have to update git
.
See "Path based filtering":
git filter-repo --path settings.json --invert-paths
Then git push --force
No need for all those repack/gc/prune at the end: the tool does the cleanup for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With