我使用了 git-filter-repo
和 filename-callback
。
stephen@B450-AORUS-M:~/source/linux$ git filter-repo --force --filename-callback '
if b"it87.c" in filename:
return filename
else:
# Keep the filename and do not rename it
return None
'
warning: Tag points to object of unexpected type tree, skipping.
warning: Tag points to object of unexpected type tree, skipping.
Parsed 935794 commitswarning: Omitting tag 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c,
since tags of trees (or tags of tags of trees, etc.) are not supported.
warning: Omitting tag 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c,
since tags of trees (or tags of tags of trees, etc.) are not supported.
Parsed 937142 commits
New history written in 177.03 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at a57e6edb85a3 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
Enumerating objects: 20210, done.
Counting objects: 100% (20210/20210), done.
Delta compression using up to 12 threads
Compressing objects: 100% (17718/17718), done.
Writing objects: 100% (20210/20210), done.
Total 20210 (delta 1841), reused 20038 (delta 1669), pack-reused 0
Completely finished after 179.76 seconds.
它没有删除空的合并提交,可能是由于与树的一侧关联的大量标签。
我尝试使用最受欢迎的答案,但似乎没有删除任何内容,并且需要很长时间。
Rewrite 3e80e1395bd4f410b79dc0f17113f5b6b409c7d8 (329/937142) (8 seconds passed, remaining 22779 predicted)
22779秒=6.3275小时
index-filter
参数应该更容易表达为git rm -r -f --cached --ignore-unmatch $(ls !(directory-to-keep))
,请参见我的答案https://dev59.com/9l3Ua4cB1Zd3GeqP8gNq#8079852和https://dev59.com/_HA85IYBdhLWcg3wBOtO#7849648。 - kynanls-tree
和| grep
之间添加| tr "\n" "\0"
(将换行符转换为 NUL),将grep -v
更改为grep -zv
,并将xargs
更改为xargs -0
(使 grep 和 xargs 期望 NUL 作为分隔符)。 - idbriils-tree
中使用-z
而不是| tr "\n" "\0"
,这样整个流水线从开始到结束都没有歧义。(因为在符合POSIX标准的文件系统中,NUL
和/
是唯一不允许出现在文件名中的两个字符。) - ssokolowgit read-tree --empty; git reset $GIT_COMMIT -- $your $files $here
就可以了。 - jthill