简体   繁体   English

从以前的所有git提交中删除.idea目录

[英]Remove .idea directory from all previous git commits

I have ~50 commits in my local Git repository. 我在我的本地Git存储库中有~50次提交。 Accidentally in the initial commit, I have included .idea folder, now I have to remove all files from that folder right from the initial commit. 无意中在初始提交中,我已经包含.idea文件夹,现在我必须从初始提交中删除该文件夹中的所有文件。 Is it possible by any chance to achieve this? 是否有可能通过任何机会实现这一目标?

I have tried the following commands but converting as separate commits without linking to previous commits: 我尝试了以下命令,但转换为单独的提交而不链接到以前的提交:

$ echo '.idea' >> .gitignore
$ git rm -r --cached .idea
$ git add .gitignore
$ git commit --amend

You can use filter-branch to do this: 您可以使用filter-branch执行此操作:

cp -r .idea .idea.bak
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r .idea' --prune-empty --tag-name-filter cat -- --all

This will remove .idea from all past commits. 这将删除所有过去提交的.idea After this, you can update the .gitignore file as you did, to avoid adding .idea in the future by mistake. 在此之后,您可以像以前一样更新.gitignore文件,以避免将来错误地添加.idea

Note that this rewrites the history of your repository. 请注意,这会重写存储库的历史记录。 If it's public and there are other collaborators, then think carefully if this is really worth it to do. 如果它是公开的并且还有其他合作者,那么请仔细考虑这是否真的值得做。

See more details at https://help.github.com/articles/removing-sensitive-data-from-a-repository/ 有关详细信息,请访问https://help.github.com/articles/removing-sensitive-data-from-a-repository/

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

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