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

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

问题描述

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

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.

我认为 git-filter-branch 一定是可能的,但我不知道如何

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

非常感谢

推荐答案

这里有一些说明做你想做的事.

这将删除file_to_remove:

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

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

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