git 从所有提交中删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35115585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove File from all Commits
提问by Yosh Iku3
I have uploaded a font file that I don't have the rights to distribute to git hub several updates ago. I have a relatively inactive repository and I have the ability to notify all of my members if necessary. I've tried several of the solutions. I need to delete a file in my directory called Resources\Video\%font%.ttf
where %font%
is the name of the plain, italicized and bold versions of the font. What commands do I use?
我在几次更新前上传了一个我无权分发到 git hub 的字体文件。我有一个相对不活跃的存储库,如有必要,我可以通知我的所有成员。我已经尝试了几种解决方案。我需要删除我的目录中的一个文件,该文件名为Resources\Video\%font%.ttf
where%font%
是字体的普通、斜体和粗体版本的名称。我使用什么命令?
回答by Gupta
In that case you could to use Git Filter Branchcommand with --tree-filter
option.
在这种情况下,您可以使用带有选项的Git Filter Branch命令--tree-filter
。
syntax is git filter-branch --tree-filter <command> ...
语法是 git filter-branch --tree-filter <command> ...
git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all
Explanation about the command:
命令说明:
< command >:Specify any shell command.
<command>:指定任何shell命令。
--tree-filter:Git will check each commit out into working directory, run your command, and re-commit.
--tree-filter:Git 将检查每个提交到工作目录中,运行您的命令,然后重新提交。
--all:Filter all commits in all branches.
--all:过滤所有分支中的所有提交。
Note: Kindly check the path for your file as I'm not sure for the file path
注意:请检查文件的路径,因为我不确定文件路径
Hope this help you !!!
希望这对你有帮助!!!
回答by karmakaze
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.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD
可以比--tree-filter
因为它只更新 git 历史而不是工作目录快得多(最多 100 倍)。
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
参考:“git filter-branch”中的“--tree-filter”和“--index-filter”有什么区别?
参考:https: //git-scm.com/docs/git-filter-branch