git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
CZChristian Zommerfelds <christian.zommerfelds@gmail.com>
Date
Jun 28, 2016, 21:15 UTC
Message-ID
<CAMS9jjwUmDi=oAi7Ew-b4+ywTLOGSuGx=YPyokpKHMqioNdmRg@mail.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

Message 1 of 1 in “subtree bug: removing and re-adding a subtree screws up the push”
  1. Christian ZommerfeldsJun 28, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.