【发布时间】:2016-10-10 21:11:04
【问题描述】:
我正在尝试进行相当复杂的 git 历史修剪,但未能找到适用于 git filter-branch 的命令。基本上我想删除除了一些匹配的文件和目录之外的所有内容。
我想运行的命令是有效的
git filter-branch -f --prune-empty --tree-filter 'rm -rf ^(FileA.java|dirB)' HEAD
但是括号中的git-filter-branch 脚本会出错。
/usr/local/Cellar/git/HEAD/libexec/git-core/git-filter-branch: eval: line 360: syntax error near unexpected token `('
/usr/local/Cellar/git/HEAD/libexec/git-core/git-filter-branch: eval: line 360: `rm -rf ^(FileA.java|dirB)'
tree filter failed: rm -rf ^(FileA.java|dirB)
我原以为 eval 可以很好地处理嵌入的括号,但这也超出了我对 shell/zsh 的理解范围。
还有git-filter-branch中的违规代码
if [ "$filter_tree" ]; then
git checkout-index -f -u -a ||
die "Could not checkout the index"
# files that $commit removed are now still in the working tree;
# remove them, else they would be added again
git clean -d -q -f -x
eval "$filter_tree" < /dev/null ||
die "tree filter failed: $filter_tree"
【问题讨论】:
标签: git shell zsh git-filter-branch