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 ?
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).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 :)