jul*_*ien 4 git history subtree git-submodules
我一直试图摆脱子模块以获得一个自包含的存储库,并且子树合并策略似乎与这个用例相匹配.
然而,合并后的回购'历史出现在我自己项目的历史中,这令人讨厌.
我已经尝试了git filter-branch --subdirectory-filter path/to/subtree/ HEAD哪些工作......直到我尝试更新一个子树,git pull -s subtree my-subtree master用于将所有子树的文件重写到项目的根目录.
有没有办法在git中实现这一点?
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"
Run Code Online (Sandbox Code Playgroud)
git子树在它生成的提交的提交消息中记录额外信息; 这些额外的信息允许它有效地进行合并,而不必合并被合并的子树的实际历史.
如果您知道永远不会对"超级"存储库中的子树进行任何更改(即子树中的所有更改将始终来自其他存储库),那么您可以不使用git子树而只重复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"
Run Code Online (Sandbox Code Playgroud)