如何从 Git 历史记录中删除文件? [英] How to remove file from Git history?
问题描述
前段时间我添加了必须是私有的信息(文件).从项目中删除不是问题,但我还需要从 git
历史记录中删除它.
Some time ago I added info(files) that must be private. Removing from the project is not problem, but I also need to remove it from git
history.
我使用 Git 和 Github(私人帐户).
I use Git and Github (private account).
注意:在这个线程上有类似的东西显示了,但这里是一个旧文件,它被添加到一个特性分支,该分支合并到一个开发分支,最后合并到主分支,因此,做了很多更改.所以它不一样,需要的是更改历史记录,并隐藏该文件以保护隐私.
Note: On this thread something similar is shown, but here is an old file that was added to a feature branch, that branch merged to a development branch and finally merged to master, since this, a lot of changes was done. So it's not the same and what is needed is to change the history, and hide that files for privacy.
推荐答案
我找到了这个答案,它有帮助:
I have found this answer and it helped:
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
在这里找到它https://myopswork.com/how-remove-files-completely-from-git-repository-history-47ed3e0c4c35
这篇关于如何从 Git 历史记录中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!