git filter-branch删除文件夹失败 [英] git filter-branch remove folder failed

查看:64
本文介绍了git filter-branch删除文件夹失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从git repo上的提交中删除一个文件夹,所以我使用以下命令:

I want to remove a folder from commits on my git repo, so I use this commend:

git filter-branch --tree-filter 'rm -rf folder' HEAD
git push origin master --force

但是我的git repo上没有任何更改,那些包含我要在git repo上删除的文件夹的提交.

But there is no any change on my git repo, those commits which contain the folder I want to delete still on git repo.

所以我再试一次,但是显示:

So I try it again, but there shows:

.git-rewrite已经存在,请将其删除

.git-rewrite already exists please remove it

我不知道还能从永久包含git repo上的文件夹的所有提交中删除它.

I don't know what else can I do to remove it from all commits which contain the folder on git repo permanently.

推荐答案

为了从git存储库中完全删除文件或目录,您必须确保不再引用该文件或目录.

In order to remove a file or directory completely from a git repository you must ensure that it is not referenced anymore.

在git中,文件(或blob对象)由树对象引用,该树对象由另一个树对象或提交对象引用.提交对象由分支,标签和引用日志中的引用进行引用.

In git a file (or blob object) is referenced by a tree object which is referenced by either another tree object or a commit object. Commit objects are referenced by branches, tags, in the reflog and so on.

前一段时间,我不得不从项目中完全删除一个文件夹,并写了一个博客.所以我不想在这里重复自己.只需看看从git页面中永久删除目录和文件.

Some time ago I had to completely remove a folder from a project and wrote a blog about it. So I don't want to repeat myself here. Just take a look at Remove directories and files permanently from git page.

我还编写了一个使用 jgit 库的swing应用程序.只需尝试 GitDirStat .最好先复制当前的回购副本.

I also wrote a swing application that uses the jgit library to to this. Just try GitDirStat. Making a copy of your current repo before is always a good choice.

.git-rewrite已经存在,请将其删除

.git-rewrite already exists please remove it

只需按照消息中的说明进行操作即可.删除 .git-rewrite .

Just do what the message says. Remove .git-rewrite.

PS:您不必使用-tree-filter ,索引过滤器可以更快地完成操作;)然后,您必须使用 git rm -rf --cached .

PS: You don't have to use a --tree-filter an index filter will do it faster ;) Then you must use git rm -rf --cached.

这篇关于git filter-branch删除文件夹失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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