我上传了一个字体文件,但在几次更新前我无权分发到 git hub。
我有一个相对不活跃的存储库,如有必要,我有能力通知我的所有成员。我已经尝试了几种解决方案。我需要删除目录中名为
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
在 Windows 中必须使用
而不是/
。\
命令说明:
< command >
指定任何 shell 命令。
--tree-filter:
Git 会将每个提交检查到工作目录中,运行命令,然后重新提交。
--index-filter:
Git 更新 git 历史记录而不是工作目录。
--all:
过滤所有分支中的所有提交。
注意: 请检查您的文件路径,因为我不确定文件路径
希望这对您有帮助。
根据官方 git 文档,强烈建议不要使用
git filter-branch
,推荐的方法是使用贡献的 git-filter-repo 命令。
安装(通过包,或使用包 python3-pip,执行 pip install:pip install git-filter-repo
)。驱魔的命令
filename
git filter-repo --invert-paths --path filename
--invert-paths
选项表示排除,不包括以下路径。
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' --prune-empty --tag--name-filter cat -- --all
git push origin --all --force
git gc --prune=now