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

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

问题描述

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



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



git rm --cached / foo 不起作用因为该文件夹已经在先前的提交中被删除。

documentation 涵盖了从历史中清除文件的类似情况:

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

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

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

请注意,此操作在较大的存储库上需要几分钟的时间。更重要的是,它将创建一个具有不同h的新存储库历史和校验。如果您以前发布过您的存储库,则新版本的历史记录与其他人的历史记录不兼容。


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

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 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

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天全站免登陆