从git历史中删除已删除的文件 [英] Remove deleted files from git history

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

问题描述

我试图从我的git存储库中分离一个子项目。
但不像
将子目录分离(移动)到单独的Git存储库
我没有它在它自己的子目录中(并且将它移入并执行上述操作只会在移动后产生历史记录)。



我克隆了我想从中分离出子项目的分支到它自己的存储库中,并删除了子项目没有使用的所有东西,所以基本上我可以使用它作为我的子项目的存储库。

现在我想摆脱不再存在于此存储库中的所有文件的历史记录,以便只保留文件的历史记录,使其进入后代。



我认为git-filter-branch一定是可以的,但我无法弄清楚

非常感谢提前

解决方案

这里有一些指令可以做你想做的事情。



这将删除 file_to_remove
$ b $ pre $ git filter-branch --index-filter'git rm --cached --ignore-unmatch file_to_remove'--prune-empty - --all


I'm trying to split a subproject off of my git repository. However unlike in Detach (move) subdirectory into separate Git repository I don't have it in it's own subdirectory (and moving it in and doing the above only yields the history after the move).

I've cloned the branch from which I want to split off the subproject into it's own repository and removed everything that isn't used by the subproject, so basically I could use this as the repository of my subproject.

Now I want to get rid of the history of all files that are no longer in this repository so as to only keep the file history for the files that made it into the offspring.

I think it must be possible with git-filter-branch but I can't figure out how

Many thanks in advance

解决方案

Here are some instructions to do what you want.

This will remove file_to_remove:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch file_to_remove' --prune-empty -- --all

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

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