从 git 存储库中完全删除文件及其历史记录
Remove Files completely from git repository along with its history
我在几次更新前上传了一个我无权分发到 git 集线器的字体文件。
我有一个相对不活跃的存储库,我可以在必要时通知我的所有成员。我已经尝试了几种解决方案。我需要删除目录中名为 Resources\Video\%font%.ttf
的文件,其中 %font%
是字体的普通、斜体和粗体版本的名称。我使用什么命令?
在这种情况下,您可以使用带有 --tree-filter
选项的 Git Filter Branch 命令。
语法是git filter-branch --tree-filter <command> ...
git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all
编辑更新
请注意 git filter-branch
--index-filter
比 --tree-filter
快得多
git filter-branch --index-filter 'rm -f Resources\Video\%font%.ttf' -- --all
In windows had to use /
instead of \
.
命令说明:
< command >
指定任何 shell 命令。
--tree-filter:
Git 将检查每个提交到工作目录,运行 你的命令,然后重新提交。
--index-filter:
Git 更新 git 历史而不是工作目录。
--all:
过滤所有分支中的所有提交。
注意:请检查您的文件路径,因为我不确定文件路径
希望对您有所帮助。
git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD
比 --tree-filter
快很多(最多 100 倍),因为它只更新 git 历史记录而不更新工作目录。
参考:What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?
参考:https://git-scm.com/docs/git-filter-branch
根据官方 git 文档,使用 git filter-branch
is strongly discouraged, and the recommended approach is to use the contributed git-filter-repo 命令。
Install it (via package, or with package python3-pip, do a pip install).
驱魔命令filename
is then:
git filter-repo --invert-paths --path filename
--invert-paths
选项表示排除,不包括以下路径。
我在几次更新前上传了一个我无权分发到 git 集线器的字体文件。
我有一个相对不活跃的存储库,我可以在必要时通知我的所有成员。我已经尝试了几种解决方案。我需要删除目录中名为 Resources\Video\%font%.ttf
的文件,其中 %font%
是字体的普通、斜体和粗体版本的名称。我使用什么命令?
在这种情况下,您可以使用带有 --tree-filter
选项的 Git Filter Branch 命令。
语法是git filter-branch --tree-filter <command> ...
git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all
编辑更新
请注意 git filter-branch
--index-filter
比 --tree-filter
git filter-branch --index-filter 'rm -f Resources\Video\%font%.ttf' -- --all
In windows had to use
/
instead of\
.
命令说明:
< command >
指定任何 shell 命令。
--tree-filter:
Git 将检查每个提交到工作目录,运行 你的命令,然后重新提交。
--index-filter:
Git 更新 git 历史而不是工作目录。
--all:
过滤所有分支中的所有提交。
注意:请检查您的文件路径,因为我不确定文件路径
希望对您有所帮助。
git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD
比 --tree-filter
快很多(最多 100 倍),因为它只更新 git 历史记录而不更新工作目录。
参考:What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?
参考:https://git-scm.com/docs/git-filter-branch
根据官方 git 文档,使用 git filter-branch
is strongly discouraged, and the recommended approach is to use the contributed git-filter-repo 命令。
Install it (via package, or with package python3-pip, do a pip install).
驱魔命令filename
is then:
git filter-repo --invert-paths --path filename
--invert-paths
选项表示排除,不包括以下路径。