apenwarr的git 子树有一个--squash
选项,它几乎可以满足您的需求。
remote=libfoo
branch=master
prefix=helpers/libfoo
git fetch "$remote" &&
git subtree add --prefix="$prefix" --squash "$remote/$branch"
: Later, once there are changes to pick up.
git subtree pull --prefix="$prefix" --squash "$remote" "$branch"
git subtree在它生成的提交的提交消息中记录额外信息;这个额外的信息允许它有效地进行合并,而不必合并被合并子树的实际历史。
如果您知道您永远不会对“超级”存储库中的子树进行任何更改(即子树中的所有更改将始终来自其他存储库),那么您可以不使用git subtree并重复git read-tree --prefix=
子树合并方法(尽管您必须先从两个索引中清除当前子树)。
remote=libfoo
branch=master
prefix=helpers/libfoo/
: replace the local subtree with whatever the other repository has
git fetch "$remote" &&
git rm -r --ignore-unmatch "$prefix" &&
git read-tree --prefix="$prefix" "${remote}/${branch}" &&
git checkout -- "$prefix" &&
git commit -m "update $prefix from $remote $branch"