【发布时间】:2013-10-30 16:45:46
【问题描述】:
我正在拆分 git repo 的一部分以创建新的 repo,并尝试使用 git filter-branch 来维护正在移动到新项目的文件的历史记录。我知道--subdirectory-filter,但这不是一个好的解决方案,因为我提取的文件并没有完全映射到一个子目录。到目前为止我发现的最佳选择是--index-filter,使用如下:
git filter-branch -f --index-filter 'git read-tree --empty && git reset -q "${GIT_COMMIT}" -- <list of files>' --prune-empty -f
这似乎可行,但我希望能够以编程方式生成要保留的文件列表,以便我可以迭代地优化此列表。我目前正在尝试获取要保留在另一个文件中的文件列表,并将其附加到代表每次提交要执行的命令的字符串中,如下所示:
tmp=$(cat ~/to_keep.txt) && git filter-branch -f --index-filter 'git read-tree --empty && git reset -q "${GIT_COMMIT}" -- '$tmp --prune-empty -f
不幸的是,这会导致
fatal: bad flag '--prune-empty' used after filename
即使只是回显文件似乎也会造成麻烦:
tmp=$(echo a.txt b.txt) && git filter-branch -f --index-filter 'git read-tree --empty && git reset -q "${GIT_COMMIT}" -- '$tmp --prune-empty -f
fatal: ambiguous argument 'b.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
我之前也尝试过连接字符串:
tmp1=$(echo a.txt b.txt) && tmp2='git read-tree --empty && git reset -q "${GIT_COMMIT}" -- ' && tmp3=${tmp2}${tmp1} && git filter-branch -f --index-filter $tmp3 --prune-empty -f
fatal: ambiguous argument 'read-tree': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
我认为这只是连接并没有像我期望的那样在 shell 中发生。有谁知道我怎样才能使这项工作?如果您也能解释这些错误的含义,那就太好了。谢谢。
【问题讨论】: