从 git 存储库中完全删除文件及其历史记录

我已经上传了一个字体文件,我没有权利分发给 github 前几次更新。

我有一个相对不活跃的存储库,如果需要,我可以通知所有成员。我已经尝试了几种解决方案。我需要在我的目录中删除一个名为 Resources\Video\%font%.ttf的文件,其中 %font%是该字体的普通、斜体和粗体版本的名称。我该使用什么命令?

51812 次浏览

In that case you could to use Git Filter Branch command with --tree-filter option.

syntax is git filter-branch --tree-filter <command> ...

git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all

Edit Updated

Note that git filter-branch --index-filter is much faster than --tree-filter

git filter-branch --index-filter 'rm -f Resources\Video\%font%.ttf' -- --all

In windows had to use / instead of \.


Explanation about the command:

< command > Specify any shell command.

--tree-filter:Git will check each commit out into working directory, run your command, and re-commit.

--index-filter: Git updates git history and not the working directory.

--all: Filter all commits in all branches.

Note: Kindly check the path for your file as I'm not sure for the file path

Hope this help you.

git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD can be much (up to 100x) faster than --tree-filter because it only updates git history and not the working directory.

ref: What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?
ref: https://git-scm.com/docs/git-filter-branch

According to the official git docs, using git filter-branch is strongly discouraged, and the recommended approach is to use the contributed git-filter-repo command.

Install it (via package, or with package python3-pip, do a pip install).

The command to exorcise filename is then:

git filter-repo --invert-paths --path filename

The --invert-paths option indicates to exclude, not include the following paths.