且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从git历史记录中删除已删除的文件夹

更新时间:2023-12-04 19:52:34

The documentation covers the similar case of purging a file from history:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD

由于要删除整个目录,因此将 -r 标志添加到 git rm :

Since you are deleting a whole directory, add the -r flag to git rm:

git filter-branch --index-filter \
                  'git rm -r --cached --ignore-unmatch path/to/directory' HEAD

请注意,此操作在大型存储库上将花费几分钟.

Note that this operation will take several minutes on larger repositories.

更重要的是,它将创建一个具有不同历史记录和校验和的新存储库.如果您以前发布了存储库,则新存储库的历史记录将与其他存储库的历史记录不兼容.

More importantly, it will make a new repository with distinct history and checksums. If you previously published your repository, the history of the new one will not be compatible with the history others have pulled.