gpt4 book ai didi

git 不再能够重写历史

转载 作者:太空狗 更新时间:2023-10-29 14:42:58 24 4
gpt4 key购买 nike

我一直在使用如下命令:

git filter-branch --index-filter \
'git ls-files -s | sed "s_subdir/__" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

将目录树从子目录“subdir”移动到顶层。为了在不同且成功的过滤器树之后清理 repo ,我尝试使用:

git filter-branch --tag-name-filter cat -- --all
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD
git reflog expire --all --expire=now
git gc --prune=now --aggressive

这混合了来自此处的一些建议。但是,执行此过滤器分支后不再有效:

Rewrite 07436df7a2795910fb0b718d1a1b84e195cfabea (1/113) (0 seconds passed, remaining 0 predicted)    mv: cannot stat ‘somepathhere/.git-rewrite/t/../index.new’: No such file or directory
index filter failed: git ls-files -s | sed "_subdir/__" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"

我完全不清楚为什么会这样,或者我使用的哪个“voodoo”清理命令负责。显然我的 git-fu 缺少一些知识。有人可以建议这可能是什么吗?

最佳答案

重写失败是因为至少有一个提交的“subdir”不存在。对我有用的修复方法是通过添加 ";/bin/true"

来更改过滤器以忽略错误
git filter-branch --index-filter \
'git ls-files -s | sed "s_subdir/__" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"; /bin/true' HEAD

这似乎等同于 --ignore-unmatch for --index-filter

我仍然不确定为什么前一个没有删除空提交:

git filter-branch --prune-empty --tag-name-filter cat -- --all
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD

但是有一个解决方案(来自 question ):

git filter-branch --parent-filter "sed 's/-p <the_commit>//'" HEAD

这会删除初始提交,它只是一个没有文件的注释(由于早期重写)。完成此操作后,可能不再需要“;/bin/true”技巧。

关于git 不再能够重写历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46651781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com