[英]remove all binary files recursively from git repo and commit history
I have read a few different threads on removing large binary files from git commit history, but my problem is just a little bit different.我已经阅读了一些关于从 git 提交历史中删除大型二进制文件的不同线程,但我的问题只是有点不同。 Hence my question here to understand and confirm the steps--
因此,我在这里提出问题以了解和确认步骤-
My git repo is ~/foo
.我的 git 仓库是
~/foo
。 I want to remove all *.jpg, *.png, *.mp4, *.ogv (and so on) from one of the directories inside the repo, specifically from ~/foo/public/data
.我想从 repo 内的目录之一中删除所有 *.jpg、*.png、*.mp4、*.ogv(等等),特别是从
~/foo/public/data
。
~/foo/data > find -E . -regex ".*\.(jpg|png|mp4|m4v|ogv|webm)" \
-exec git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch {}' \
--prune-empty --tag-name-filter cat -- --all \;
~/foo/data > cd ..
~/foo > git add .gitignore
~/foo > git commit -m "added binary files to .gitignore"
~/foo > git push origin master --force
Am I on the right track above?我在上面的正确轨道上吗? I want to measure twice before I cut once, so to say.
我想在切割一次之前测量两次,可以这么说。
Update: Well, the above gives me the error更新:嗯,上面给了我错误
You need to run this command from the toplevel of the working tree.
You need to run this command from the toplevel of the working tree.
..
So I went up the tree to the top level and re-ran the command, and it all worked.所以我爬上树到顶层并重新运行命令,一切都奏效了。
The process seems right.这个过程似乎是正确的。
You can also test your clean process with a tool like bfg repo cleaner , as in this answer :您还可以使用bfg repocleaner 之类的工具测试您的清理过程,如以下答案所示:
java -jar bfg.jar --delete-files *.{jpg,png,mp4,m4v,ogv,webm} ${bare-repo-dir};
(Except BFG makes sure it doesn't delete anything in your latest commit, so you need to remove those files in the current index and make a "clean" commit. All other previous commits will be cleaned by BFG) (除了 BFG 确保它不会删除您最新提交中的任何内容,因此您需要删除当前索引中的那些文件并进行“干净”提交。所有其他以前的提交将由 BFG 清除)
Update 2020: for removing files, you would now use git filter-repo
(Git 2.22+, Q4 2019), since git filter-branch
or BFG
are now, 7 years later, obsolete . 2020 年更新:对于删除文件,您现在将使用
git filter-repo
(Git 2.22+,2019 年第四季度),因为git filter-branch
或BFG
现在已经过时了,7 年后。
git filter-repo --path fileToRemove --invert-paths
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.