Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reduce the ever-increasing time to push a subtree?

Tags:

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?

like image 676
ferraith Avatar asked Apr 21 '13 18:04

ferraith


People also ask

How do you push a subtree?

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

How do you make a subtree?

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.


2 Answers

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.

like image 132
Maic López Sáenz Avatar answered Oct 08 '22 06:10

Maic López Sáenz


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.

like image 40
Chronial Avatar answered Oct 08 '22 07:10

Chronial