警告:git-filter-branch 有大量陷阱,会产生损坏的历史重写

acg*_*box 5 bash git

我想从本地 git 存储库中清理一个大文件(顺便清理我的存储库以减小大小)。这是我的狂欢:

#!/bin/bash
bigfile="/path_to_mygitproject/bigfile.tar.gz"
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch '"$bigfile"'' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch '"$bigfile"'' HEAD

Run Code Online (Sandbox Code Playgroud)

但现在显示以下警告:

WARNING: git-filter-branch has a glut of gotchas generating mangled history
     rewrites.  Hit Ctrl-C before proceeding to abort, then use an
     alternative filtering tool such as 'git filter-repo'
     (https://github.com/newren/git-filter-repo/) instead.  See the
     filter-branch manual page for more details; to squelch this warning,
     set FILTER_BRANCH_SQUELCH_WARNING=1.
Run Code Online (Sandbox Code Playgroud)

我一直用这个bash,从来没有遇到过问题。到目前为止。我猜 git 中发生了一些变化。

我尝试将“git filter-branch”替换为“git filter-repo”,但收到消息:

git: 'filter-repo' is not a git command. Look at 'git --help'.but
Run Code Online (Sandbox Code Playgroud)

我应该解决什么问题?谢谢

更新:

我这样做了,但似乎一切都改变了

wget https://raw.githubusercontent.com/newren/git-filter-repo/master/git-filter-repo -O /home/user/.local/bin/git-filter-repo
chmod +x /home/user/.local/bin/git-filter-repo
Run Code Online (Sandbox Code Playgroud)

并将我的脚本中的“git filter-branch”替换为“git filter-repo”。出去:

git-filter-repo: error: argument --prune-empty: expected one argument
git-filter-repo: error: unrecognized arguments: --index-filter git rm -r --cached --ignore-unmatch bigfile.tar.gz HEAD
Run Code Online (Sandbox Code Playgroud)

我检查了示例并添加了“--prune-empty auto”,但我无法修复我的脚本,因为我不知道“--index-filter”或“--tag-name-”的替代品是什么过滤器”将是(似乎它们不存在)

git filter-repo --version
ffc6fa9265d8
git --version
git version 2.25.1
Run Code Online (Sandbox Code Playgroud)

更新:

我已成功使用以下命令减小了存储库的大小:

git filter-repo --strip-blobs-bigger-than 10M
Run Code Online (Sandbox Code Playgroud)

但这是一个不合适的方法,因为我可以删除其他大于10M并且我不想被删除的文件

解决了!

git filter-repo --path bigfile.tar.gz --invert-paths
Run Code Online (Sandbox Code Playgroud)

投票结果接近