{"thread":{"id":"39396","subject":"Issue when merging a subtree whose a file has been removed","startedAt":"2015-05-21T15:40:05Z","lastAt":"2015-05-21T15:40:05Z","messageCount":1,"participants":["adatoccpptranslator@free.fr"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"261792","messageId":"1191356813.419782668.1432222805047.JavaMail.root@zimbra41-e7.priv.proxad.net","threadId":"39396","inReplyTo":"160239201.419722978.1432221938533.JavaMail.root@zimbra41-e7.priv.proxad.net","subject":"Issue when merging a subtree whose a file has been removed","fromName":"","fromEmail":"adatoccpptranslator@free.fr","sentAt":"2015-05-21T15:40:05Z","receivedAt":"2015-05-21T15:40:05Z","isPatch":false,"sender":{"key":"adatoccpptranslator@free.fr","avatar":null},"body":"Hi all,\n\nI want to use subtrees in one of my projects and I use method desribed here https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging\nI`m facing issues when merging subtree in my subproject in case some files have been removed from the subtree.\n\nI`m running git 1.9.1 on Kubuntu  14.04\nsub_project is integrated as subtree in my main project. I modify a file and remove an other file from my sub_project, commit the modification, go in my main_project, checkout the sub_project integration branch, pull the modification.\nI see the modification of the modified file and the deletion of the removed file\nI checkout the master branch of my main project.\ngit diff-tree -p sub_project_branch indicate that one file has been modified and one files has been deleted\nthen I perform a merge of my subtree integration branch into master branch.\n\nHere are the corresponding commands:\n#!/bin/sh\n\n# Creating project that will be used as subtree\n$ mkdir sub_project\n$ cd sub_project\n$ git init\n$ touch toto\n$ echo \"-----------------\" >> toto\n$ echo \"- toto file\">> toto\n$ echo \"-----------------\" >> toto\n$ touch tata\n$ echo \"-----------------\" >> tata\n$ echo \"- tata file\">> tata\n$ echo \"-----------------\" >> tata\n$ git add toto tata\n$ git commit -m \"Initial commit\"\n$ echo \"echo toto\" >> toto\n$ echo \"echo tata\" >> tata\n$ git commit -am \"Add content to file\"\n$ cd ..\n\n# Creating main project that will use the subtree\n$ mkdir main_project\n$ cd main_project\n$ git init\n$ touch tutu\n$ echo \"-----------------\" >> tutu\n$ echo \"- tutu file\">> tutu\n$ echo \"-----------------\" >> tutu\n$ git add tutu\n$ git commit -m \"Add tutu file\"\n# Creation of subtree\n$ mkdir sources\n$ git remote add sub_project_remote ../sub_project\n$ git fetch sub_project_remote\n$ git checkout -b sub_project_branch sub_project_remote/master\n$ git checkout master\n$ git read-tree --prefix=sources/sub_project/ -u sub_project_branch\n$ git commit -am \"Integration of subtree\"\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Subtree well integrated \"\nSubtree well integrated \n$ ls *\ntutu\n\nsources:\nsub_project\n$ ls sources/sub_project\ntata\ntoto\n$ echo \"------------------------\"\n------------------------\n\n# Go in subtree to remove tata file\n$ cd ../sub_project\n$ echo \"#EOF\" >> toto\n$ git add toto\n$ git rm tata\n$ git commit -m \"Add EOF and remove tata\"\n\n# go back in main project to integrate subtree modifications\n$ cd ../main_project\n$ git checkout sub_project_branch\n$ git fetch sub_project_remote\n$ git pull\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Check that tata has been removed \"\nCheck that tata has been removed \n$ ls *\ntoto\n$ echo \"------------------------\"\n------------------------\n\n$ git checkout master\n$ git diff-tree -p sub_project_branch\ndiff --git a/tata b/tata\ndeleted file mode 100644\nindex a4f4cc4..0000000\n--- a/tata\n+++ /dev/null\n@@ -1,4 +0,0 @@\n------------------\n-- tata file\n------------------\n-echo tata\ndiff --git a/toto b/toto\nindex 8dfbe14..98ae756 100644\n--- a/toto\n+++ b/toto\n@@ -2,3 +2,4 @@\n - toto file\n -----------------\n echo toto\n+#EOF\n\n$ git merge -v --squash --no-commit -X subtree=sources/sub_project -X theirs sub_project_branch\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Check after merge that tata has been removed \"\nCheck after merge that tata has been removed \n$ ls sources/*\ntata\ntoto\n$ echo \"------------------------\"\n------------------------\n$ git commit -m \"Second integration from subtree\"\n$ cd ..\n#EOF\n\nI was expecting to see the in master the modification of the file and the deletion of the other file but the removed file is still there and tracked. The modification of file has been done but It looks like the deletion has not been \"merged\".\n\nThe behaviour I expect is the same that the one illustrated in command sequence below which perform exactly the same actions excepted they are done in a branch instead of a subtree:\ntoto should have been modified, tata should no more be there or at least no more be tracked\n#!/bin/sh\n$ git init\n$ touch toto\n$ echo \"-----------------\" >> toto\n$ echo \"- toto file\">> toto\n$ echo \"-----------------\" >> toto\n$ touch tata\n$ echo \"-----------------\" >> tata\n$ echo \"- tata file\">> tata\n$ echo \"-----------------\" >> tata\n$ git add toto tata\n$ git commit -m \"Initial commit\"\n$ echo \"echo toto\" >> toto\n$ echo \"echo tata\" >> tata\n$ git commit -am \"Add content to file\"\n$ git checkout -b headers\n$ echo \"#EOF\" >> toto\n$ git add toto\n$ git rm tata\n$ git commit -m \"Add EOF and remove tata\"\n$ git checkout master\n$ touch tutu\n$ echo \"-----------------\" >> tutu\n$ echo \"- tutu file\">> tutu\n$ echo \"-----------------\" >> tutu\n$ git add tutu\n$ git commit -m \"Add tutu file\"\n$ git merge -m \"Merge from headers branch\" headers\nMerge made by the 'recursive' strategy.\n tata | 4 ----\n toto | 1 +\n 2 files changed, 1 insertion(+), 4 deletions(-)\n delete mode 100644 tata\n[master a9cad6d] Add EOF\n 1 file changed, 1 insertion(+)\n$ echo \"#EOF\" >> tutu\n$ git add tutu\n$ git commit -m \"Add EOF\"\n$ ls\ntoto\ntutu\n#EOF\n\n\nAccording to what I see it seems that the subtree merge is doing a kind of copy instead of a real merge meaning that if source file disappear then the corresponding target file is untouched instead of being deleted.\nIs this behaviour correct or is it my understanding of what subtree merge should do that is wrong ?\n\n\nThanks by advance\nJulien\n\nPS : as my subtree prefix has 2 levels I also test with a single level like in subtree tutorial to ensure this was not the cause of my issue but the problem remains the same. the single level test is performed by the following command sequence:\n\n#!/bin/sh\n\n# Creating project that will be used as subtree\n$ mkdir sub_project\n$ cd sub_project\n$ git init\n$ touch toto\n$ echo \"-----------------\" >> toto\n$ echo \"- toto file\">> toto\n$ echo \"-----------------\" >> toto\n$ touch tata\n$ echo \"-----------------\" >> tata\n$ echo \"- tata file\">> tata\n$ echo \"-----------------\" >> tata\n$ git add toto tata\n$ git commit -m \"Initial commit\"\n$ echo \"echo toto\" >> toto\n$ echo \"echo tata\" >> tata\n$ git commit -am \"Add content to file\"\n$ cd ..\n\n# Creating main project that will use the subtree\n$ mkdir main_project\n$ cd main_project\n$ git init\n$ touch tutu\n$ echo \"-----------------\" >> tutu\n$ echo \"- tutu file\">> tutu\n$ echo \"-----------------\" >> tutu\n$ git add tutu\n$ git commit -m \"Add tutu file\"\n# Creation of subtree\n$ git remote add sub_project_remote ../sub_project\n$ git fetch sub_project_remote\n$ git checkout -b sub_project_branch sub_project_remote/master\n$ git checkout master\n$ git read-tree --prefix=sub_project/ -u sub_project_branch\n$ git commit -am \"Integration of subtree\"\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Subtree well integrated \"\nSubtree well integrated\n$ ls *\ntutu\n\nsub_project:\ntata\ntoto\n$ echo \"------------------------\"\n------------------------\n\n# Go in subtree to remove tata file\n$ cd ../sub_project\n$ echo \"#EOF\" >> toto\n$ git add toto\n$ git rm tata\n$ git commit -m \"Add EOF and remove tata\"\n\n# go back in main project to integrate subtree modifications\n$ cd ../main_project\n$ git checkout sub_project_branch\n$ git fetch sub_project_remote\n$ git pull\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Check that tata has been removed \"\nCheck that tata has been removed \n$ ls *\ntoto\n$ echo \"------------------------\"\n------------------------\n\n$ git checkout master\n$ git diff-tree -p sub_project_branch\ndiff --git a/tata b/tata\ndeleted file mode 100644\nindex a4f4cc4..0000000\n--- a/tata\n+++ /dev/null\n@@ -1,4 +0,0 @@\n------------------\n-- tata file\n------------------\n-echo tata\ndiff --git a/toto b/toto\nindex 8dfbe14..98ae756 100644\n--- a/toto\n+++ b/toto\n@@ -2,3 +2,4 @@\n - toto file\n -----------------\n echo toto\n+#EOF\n$ git merge -v --squash --no-commit -s subtree -X theirs sub_project_branch\n\n$ echo \"------------------------\"\n------------------------\n$ echo \"Check after merge that tata has been removed \"\nCheck after merge that tata has been removed \n$ ls *\ntutu\n\nsub_project:\ntata\ntoto\n$ echo \"------------------------\"\n------------------------\n$ git commit -m \"Second integration from subtree\"\n$ cd ..\n#EOF\n"}]}