简体   繁体   中英

How to remove GitHub commit along with it's history?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM