My friend made a config file, holding our apikey/token/secrets, and a .gitignore
to ignore said file. Someone accidentally pushed to the master branch with the config file saved as another name and is now showing.
I was wondering if there was a way to delete that commit and the history of that commit.
I have seen this (below) and I understand this will delete the commit and re-push everything. But it still shows the config info via history/changes:
git reset --hard hash#
git push -f origin branch
git-filter-branch can help you in your case, as follows:
Replace PATH-TO-YOUR-CONFIG-FILE
with the path to your config file you want to remove, not just its filename.
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch PATH-TO-YOUR-CONFIG-FILE' \
--prune-empty --tag-name-filter cat -- --all
Add your config file to .gitignore
to ensure that you don't accidentally commit it again, commit and push it, following below commands:
echo "YOUR-CONFIG-FILE" >> .gitignore
git add .gitignore
git commit -m "Add YOUR-CONFIG-FILE to .gitignore"
git push origin --force --all
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