简体   繁体   中英

Removing .gitignore files from previous commits in GitHub

I recently added a file to my .gitignore, but my repository contains previous commits that include that file. Commits from here on out no longer track the ignored file thanks to using

git rm --cached config/secrets.yml

Is there a quick git command that will go through all of my previous commits and remove that file from showing in my commit history?

It's not easy. You have to go through each commit and remove that file. And keep in mind that will modify the history, be careful if you are collaborating with others.

Here is a guide from GitHub on how to remove sensitive data: https://help.github.com/articles/remove-sensitive-data/

The resulting command should be:

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch config/secrets.yml' \
--prune-empty --tag-name-filter cat -- --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