gpt4 book ai didi

git - 我如何使用正则表达式 git filter-branch 从历史记录中永久删除文件/目录?

转载 作者:太空狗 更新时间:2023-10-29 14:48:16 28 4
gpt4 key购买 nike

有没有办法通过 git filter-branch 正则表达式从历史记录中永久删除文件/目录?

最佳答案

假设你想做一个索引过滤器(不需要改变你的工作树),你可以在所有提交上编写脚本,并且只通过 sed,egrep 或 grep 在 的输出上改变你需要的文件git ls-files.

git ls-files --cached | \
sed 's/weirdprefix\(pattern\)/git reset HEAD weirdprefix\1/g' | \
xargs -i{} sh -c '{}'

(这是您将在 filter-branch 命令中提供的脚本)

这是文档 ( http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html ) 中的示例:

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

关于git - 我如何使用正则表达式 git filter-branch 从历史记录中永久删除文件/目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12607643/

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