简体   繁体   English

从GitHub中的先前提交中删除.gitignore文件

[英]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. 我最近在.gitignore中添加了一个文件,但是我的存储库中包含以前包含该文件的提交。 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? 是否有一个快速的git命令可以通过我之前的所有提交,并将该文件从提交历史记录中删除?

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/ 这是GitHub上有关如何删除敏感数据的指南: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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