threads / bug / 42738

subtree bug: removing and re-adding a subtree screws up the push

Subject: subtree bug: removing and re-adding a subtree screws up the push

## tl;dr

One message between Jun 28, 2016 and Jun 28, 2016.

replies: 0people: 1as markdown or json

Christian Zommerfelds· Jun 28, 2016, 21:15 UTC · lore
Hi,

Today I realized that when you add a subtree with `git subtree add`, then remove it with `git rm -r`, then re-add it again, pushing to the subtree behaves weirdly: it adds the whole history of the main repository to the sub repository.

Below is a list of commands to reproduce the issue:

``` mkdir myproj mkdir mylib

cd mylib touch mylib-file1 git init git add mylib-file1 git commit -m "mylib initial commit"

cd ../myproj touch myproj-file1 git init git add myproj-file1 git commit -m "myproj initial commit" git subtree add --squash -P contrib/mylib -m "added lib" ../mylib master git rm -r contrib/mylib git commit -m "removed lib" git subtree add --squash -P contrib/mylib -m "re-adding lib" ../mylib master

git subtree push -P contrib/mylib ../mylib test

cd ../mylib git checkout test git log | cat # expected: only "mylib initial commit" # actual: full history of myproj ```

If you replace the last two occurrences of contrib/mylib by a different folder such as contrib2/mylib, the push works as usual. I suspect that subtree splits using the first commit in the subfolder in the whole history, rather than the first commit after the folder was last added.

Best regards, Christian Zommerfelds

← back to recent threads