{"thread":{"id":"42738","subject":"subtree bug: removing and re-adding a subtree screws up the push","startedAt":"2016-06-28T21:15:38Z","lastAt":"2016-06-28T21:15:38Z","messageCount":1,"participants":["Christian Zommerfelds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"290438","messageId":"CAMS9jjwUmDi=oAi7Ew-b4+ywTLOGSuGx=YPyokpKHMqioNdmRg@mail.gmail.com","threadId":"42738","inReplyTo":null,"subject":"subtree bug: removing and re-adding a subtree screws up the push","fromName":"Christian Zommerfelds","fromEmail":"christian.zommerfelds@gmail.com","sentAt":"2016-06-28T21:15:32Z","receivedAt":"2016-06-28T21:15:38Z","isPatch":false,"sender":{"key":"christian.zommerfelds@gmail.com","avatar":null},"body":"Hi,\n\nToday I realized that when you add a subtree with `git subtree add`,\nthen remove it with `git rm -r`, then re-add it again, pushing to the\nsubtree behaves weirdly: it adds the whole history of the main\nrepository to the sub repository.\n\nBelow is a list of commands to reproduce the issue:\n\n```\nmkdir myproj\nmkdir mylib\n\ncd mylib\ntouch mylib-file1\ngit init\ngit add mylib-file1\ngit commit -m \"mylib initial commit\"\n\ncd ../myproj\ntouch myproj-file1\ngit init\ngit add myproj-file1\ngit commit -m \"myproj initial commit\"\ngit subtree add --squash -P contrib/mylib -m \"added lib\" ../mylib master\ngit rm -r contrib/mylib\ngit commit -m \"removed lib\"\ngit subtree add --squash -P contrib/mylib -m \"re-adding lib\" ../mylib master\n\ngit subtree push -P contrib/mylib ../mylib test\n\ncd ../mylib\ngit checkout test\ngit log | cat\n# expected: only \"mylib initial commit\"\n# actual: full history of myproj\n```\n\nIf you replace the last two occurrences of contrib/mylib by a\ndifferent folder such as contrib2/mylib, the push works as usual. I\nsuspect that subtree splits using the first commit in the subfolder in\nthe whole history, rather than the first commit after the folder was\nlast added.\n\nBest regards,\nChristian Zommerfelds\n"}]}