Github: 单独删除某个文件的所有历史记录
背景:
我手头有个项目,因为之前没注意,把公网环境的IP地址,数据库写到了Github。
但是项目已经提交100多次.这个时候我只想单纯的把这个application-test.yml删掉,包括历史记录
网上一大堆,都感觉是一个人写的,全部在复制粘贴。很是无语。
直接看官网文档:
https://help.github.com/articles/removing-sensitive-data-from-a-repository/
看我的Git记录:
1.
cd 你的项目
2.
我要删掉记录的文件的路径是(相对于项目):
src/main/resources/config/application-test.yml
3. 把src/main/resources/config/application-test.yml替换成你们自己的
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/main/resources/config/application-test.yml' --prune-empty --tag-name-filter cat -- --all
4. 本地记录覆盖到Github,(所有branch以及所有tags)
git push origin --force --all
git push origin --force --tags
5. 确保没有什么问题之后,强制解除对本地存储库中的所有对象的引用和垃圾收集
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
你会发现,GitHub上关于config/application-test.yml的记录都不见了
注意:为了避免以后又提交config/application-test.yml,你们可以把这个文件添加到.ignore中,忽略提交