从git历史记录中删除已删除的文件夹 [英] Remove a deleted folder from git history

查看:55
本文介绍了从git历史记录中删除已删除的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I remove a folder that is already deleted from the git history?

在我的git存储库中,我有一个名为/foo 的文件夹(大小为1.2GB).我用 rm -rf/foo 删除了 foo 文件夹,因为我不再需要它了.经过许多其他的承诺,我想.为什么我的远程仓库如此之大...我忘了做 git rm --cached ... 而不是 rm -rf ... .现在如何从git历史记录中删除该文件夹?

In my git repository I have a folder called /foo (1.2GB of size). I have deleted the folder foo with rm -rf /foo beause I do not need it any more. After many other commits I thought. Why is my remote repo so big...I have forgotten to do git rm --cached ... instead of rm -rf .... How can I now remove the folder from git history?

git rm --cached/foo 无效,因为该文件夹已在较早的提交中删除.

git rm --cached /foo won't work because the folder is already delete in an earlier commit.

推荐答案

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.

这篇关于从git历史记录中删除已删除的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆