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

1 messages from 2016-06-28 to 2016-06-28. Participants: Christian Zommerfelds.
Thread: https://gitlist.dev/t/42738

## Christian Zommerfelds, 2016-06-28 21:15

Subject: subtree bug: removing and re-adding a subtree screws up the push
Message-ID: <CAMS9jjwUmDi=oAi7Ew-b4+ywTLOGSuGx=YPyokpKHMqioNdmRg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMS9jjwUmDi%3DoAi7Ew-b4%2BywTLOGSuGx%3DYPyokpKHMqioNdmRg%40mail.gmail.com

```
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

```
