I'm using Git subtree to "link" several subprojects into the main project (I'm coming from "svn:externals"). I've used it for some weeks, but the time to push changes to the subtree remote increases every commit.
$ git subtree push -P platform/rtos rtos master
git push using: rtos master
1/ 215 (0)2/ 215 (1)3/ 215 (2)4/ 215 (3)5/ 215 (4)6/ 215 (5)7/ 215 (6)8/ 215 (7)9/ 215 (8)10/ 215 (9)11/ 215 (9)12/ 215 (10)13/ 215 (11)14/
...
20 more lines
...
(204)209/ 215 (205)210/ 215 (206)211/ 215 (207)212/ 215 (208)213/ 215 (209)214/ 215 (210)215/ 215 (211)To https://github.com/rtos/rtos.git
64546f..9454ce 9a9d34c5656655656565676768887899898767667348590 -> master
Is there any way to "clean up" the subtree and therefore reduce the time to push changes?
To push commits back to a subtree, select the (remote) subtree branch in the Branches view and invoke Remote|Subtree|Push. Pushing a subtree involves splitting changes back from main repository to subtree repository (more details can be found below).
Adding a subtreeSpecify the prefix local directory into which you want to pull the subtree. Specify the remote repository URL [of the subtree being pulled in] Specify the remote branch [of the subtree being pulled in] Specify you want to squash all the remote repository's [the subtree's] logs.
Try using the --rejoin
flag, so that after the split the subtree is correctly merged back to your main repository. This way each split needs not to go through all history.
git subtree split --rejoin --prefix=<prefix> <commit...>
From the original subtree documentation:
After splitting, merge the newly created synthetic history back into your main project. That way, future splits can search only the part of history that has been added since the most recent --rejoin.
No, unfortunately not. When you run git subtree push
, it will recreate all commits for this subtree. It has to do that, as their SHA depends on the previous commit and needs those SHAs to be able to link the new commits to the old ones. It could cache that, but it doesn’t.
I guess this is the price you pay for using subtree vs. submodules. Subtree is very stateless in your repository, which is nice on the one hand but causes these long computations on the other hand. Submodules store all their information which requires you to manage it but also makes stuff like this a lot faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With