Git子树合并策略,可以不合并历史记录吗?
我一直在尝试摆脱子模块以获得独立的存储库,以及 子树合并策略似乎符合这个用例。
然而,合并的存储库的历史出现在我自己的项目的历史中,这相当烦人。
我尝试过 git filter-branch --subdirectory-filter path/to/subtree/ HEAD ,它有效......直到我尝试使用 git pull -s subtree my- 更新子树subtree master 它将所有子树的文件重写到我的项目的根目录。
有没有办法在 git 中本地实现这一点?
I've been trying to move away from submodules in order to get a self-contained repository, and the subtree merge strategy seems to match this use-case.
However the merged repos' histories appear in my own project's history, which is reather annoying.
I've tried git filter-branch --subdirectory-filter path/to/subtree/ HEAD
which works... until I try to update a subtree with git pull -s subtree my-subtree master
which rewrites all the subtree's files to my project's root.
Is there a way to achieve this natively in git ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
apenwarr 的 git 子树 有一个
--squash
选项,它可能几乎可以满足您的需求。git 子树 在它生成的提交的提交消息中记录额外信息;这些额外的信息使其能够有效地进行合并,而无需合并正在合并的子树的实际历史记录。
如果您知道您永远不会对“超级”存储库中的子树进行任何更改(即子树中的所有更改将始终来自其他存储库),那么您可以不用 git subtree并只需重复子树合并方法的 git read-tree --prefix= 部分(尽管您必须首先从两个索引中清除当前的子树)。
apenwarr’s git subtree has a
--squash
option that might do very nearly what you want.git subtree records extra information in the commit messages of the commits it generates; this extra information allows it to effectively do merges without having to incorporate the actual history of the subtree being merged.
If you know that you will never make any changes to the subtree in the “super” repository (i.e. all the changes in the subtree will always come from some other repository), then you could do without git subtree and just repeat the
git read-tree --prefix=
part of the subtree merge method (though you have to clean out your current subtree from both the index first).如果这只是阅读“git log”时的烦恼,那么您可能想尝试:
它只显示您的提交和(单个)合并提交,但不显示远程的提交。
如果您想通过差异查看它(这将为合并提交创建一个大差异):
不需要额外的工具:)
If it is just an annoyance when reading 'git log', then you might want to try:
It only shows your commits and the (single) merge commits, but not the commits of the remote.
If you want to see it with a diff (which will create one big diff for the merge commits):
No extra tools needed :)