{"thread":{"id":"11559","subject":"Re: [PATCH] Add [HOWTO] using merge subtree.","startedAt":"2008-01-09T22:33:26Z","lastAt":"2008-01-15T00:35:02Z","messageCount":2,"participants":["Junio C Hamano","Miklos Vajna"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64880","messageId":"7vabnefx3d.fsf@gitster.siamese.dyndns.org","threadId":"11559","inReplyTo":"1199882097-10420-1-git-send-email-vmiklos@frugalware.org","subject":"Re: [PATCH] Add [HOWTO] using merge subtree.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-09T22:33:26Z","receivedAt":"2008-01-09T22:33:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@frugalware.org> writes:\n\n> here is an updated version. i added a section (before the commands) to\n> describe the workflow where the subtree merge strategy can be useful. i\n> also added a section at the end where i mention submodules.\n\nThat's better.\n\n> @@ -0,0 +1,48 @@\n> +Date: Sat, 5 Jan 2008 20:17:40 -0500\n> +From: Sean <seanlkml@sympatico.ca>\n> +To: Miklos Vajna <vmiklos@frugalware.org>\n> +Cc: git@vger.kernel.org\n> +Subject: Re: how to use git merge -s subtree?\n> +Abstract: In this article, Sean demonstrates how one can use the subtree merge\n> + strategy.\n> +Message-ID: <BAYC1-PASMTP12374B54BA370A1E1C6E78AE4E0@CEZ.ICE>\n> +\n> +How to use the subtree merge strategy\n> +=====================================\n> +\n> +The merge strategy 'subtree' is a slightly modified 'recursive'.  It merges\n> +current branch A with other branch B using common merge base O (and if there\n> +are more than one common merge bases, they are recursively merged), but it can\n> +\"shift\" trees while doing so.\n> +\n> +This can be handy if you want to merge a branch to a subdirectory, for example\n> +git has the git-gui master branch in its git-gui/ subdirectory.\n> +\n> +So the target is to merge a branch of repo B to a subdirectory of the current\n> +branch.\n> +\n> +You need the followings steps to perform the master branch of B to the\n> +subdirectory B/ for the first merge:\n\nI think the presentation order is still screwy.  Before saying\nwhat it does, let's state why the reader might want to use what\nwe are going to describe, so that the reader can say \"I am not\nin that situation, I do not have to read the rest\" and skip the\ndocument quickly.\n\n    When you want to include contents in your project from\n    another project that has started its life independently, you\n    can do so by merging the other project into your project.\n    If there is no (and more importantly if there will never be\n    any) overlap in paths the two project have, you can merge\n    them without any tricks.\n\n    However, if there are overlapping paths (e.g. you have\n    Makefile, they have Makefile but as separate projects, these\n    two Makefiles do not have anything to do with each other),\n    you have a problem.  You do not necessarily have the option\n    to merge these Makefiles together.  Instead, you may want to\n    merge the other project as a subdirectory in your project.\n\n    The 'subtree' merge strategy is designed to help you in such\n    a situation.\n\nThen give the birds-eye-view of the names you use in the example\ndescription, so that the readers can substitute them to suit\ntheir needs:\n\n    Suppose you are merging the \"master\" branch of another\n    project located at /path/to/B (the repository does not have\n    to be local but we use /path/to/B for the sake of\n    simplicity) as a subdirectory \"dir-B\" in our project.  Here\n    is the procedure to bootstrap and maintain such a layout.\n\n> +----\n> +$ git remote add -f B /path/to/B <1>\n> +$ git merge -s ours --no-commit B/master <2>\n> +$ git read-tree --prefix=B/ -u B/master <3>\n> +$ git commit -m \"Merge commit 'B/master'\" <4>\n> +$ git pull -s subtree B master <5>\n> +----\n> +<1> creates and fetches the remote.\n> +<2> initiates a merge, but stops before committing it.\n> +<3> reads B/master into the subdirectory \"sub\".\n> +<4> all that remains is committing the completed merge.\n>\n> +You only need the above four steps once, after that you can keep doing:\n> +\n> +----\n> +$ git pull -s subtree B master\n> +----\n\nThis part looks like a half-updated WIP.\n\n    ----------------\n    $ git remote add -f Bproject /path/to/B <1>\n    $ git merge -s ours --no-commit B/master <2>\n    $ git read-tree --prefix=dir-B/ -u B/master <3>\n    $ git commit -m \"Merge B project as our subdirectory\" <4>\n\n    $ git pull -s subtree Bproject master <5>\n    ----------------\n    <1> name the other project \"Bproject\", and fetch.\n    <2> prepare for the later step to record the result as a merge.\n    <3> read \"master\" branch of Bproject to the subdirectory \"dir-B\".\n    <4> record the merge result.\n    <5> maintain the result with subsequent merges using \"subtree\"\n    \nThen the discussion.\n\n> +The benefit of the subtree merge strategy over submodules is that submodules\n> +were not always available and it may still make sense to avoid it today,\n> +because use of a submodule in a repository makes the repository\n> +non-interoperable with any clients older than 1.5.2 series.\n\nThat's not incorrect, but I think we would need to discuss more\nimportant matters first.  The discussion should consist of two\nparts.\n\nFirst, the tips, tricks and caveats when using subtree merge.\n\n - The participant to your project may want to make changes\n   pertaining to the subtree merged project independently and\n   send the result upward, although it is not required (the\n   other project can merge from your project using subtree --\n   the subtree strategy can shift your tree up and let the other\n   project merge only the parts of your tree that corresponds to\n   it).\n\n - The other project may not choose to.  One possible reason not\n   to is if it does not want to connect its history to yours\n   (although you wanted to do so in your repository).\n\nAnd comparison with an alternative, \"submodules\":\n\n - It is simpler to merge another project using subtree than\n   treating the other project as \"submodule\", due to less\n   management hassles (pro).\n\n - It ties the two histories together as equals.  If the other\n   project chooses to also use subtree merge from you, the two\n   histories will be tied very closely, which often is not\n   desirable from the point of view of the \"contained\" project\n   (con).\n\n - It does not allow \"narrow checkout\" and \"narrow clone\" as\n   submodule does (con).\n"},{"id":"65353","messageId":"20080115003502.GN29972@genesis.frugalware.org","threadId":"11559","inReplyTo":"7vabnefx3d.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Add [HOWTO] using merge subtree.","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-01-15T00:35:02Z","receivedAt":"2008-01-15T00:35:02Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nHere comes the 3rd try. I wonder if I should remove the mail header :) The\ncommands are from the mail, but the patch itself now are more based on the\nsuggestions by Junio (and reworded / reorganized).\n\nSorry for the late reply, I had some problem with my mail setup.\n\n Documentation/Makefile                    |    2 +-\n Documentation/howto/use-merge-subtree.txt |   71 +++++++++++++++++++++++++++++\n 2 files changed, 72 insertions(+), 1 deletions(-)\n create mode 100644 Documentation/howto/use-merge-subtree.txt\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex 7b0685b..4addb8a 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -23,7 +23,7 @@ ARTICLES += everyday\n ARTICLES += git-tools\n ARTICLES += glossary\n # with their own formatting rules.\n-SP_ARTICLES = howto/revert-branch-rebase user-manual\n+SP_ARTICLES = howto/revert-branch-rebase howto/use-merge-subtree user-manual\n API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technical/api-index.txt, $(wildcard technical/api-*.txt)))\n SP_ARTICLES += $(API_DOCS)\n SP_ARTICLES += technical/api-index\ndiff --git a/Documentation/howto/use-merge-subtree.txt b/Documentation/howto/use-merge-subtree.txt\nnew file mode 100644\nindex 0000000..2f4f38a\n--- /dev/null\n+++ b/Documentation/howto/use-merge-subtree.txt\n@@ -0,0 +1,71 @@\n+Date: Sat, 5 Jan 2008 20:17:40 -0500\n+From: Sean <seanlkml@sympatico.ca>\n+To: Miklos Vajna <vmiklos@frugalware.org>\n+Cc: git@vger.kernel.org\n+Subject: Re: how to use git merge -s subtree?\n+Abstract: In this article, Sean demonstrates how one can use the subtree merge\n+ strategy.\n+Message-ID: <BAYC1-PASMTP12374B54BA370A1E1C6E78AE4E0@CEZ.ICE>\n+\n+How to use the subtree merge strategy\n+=====================================\n+\n+There are situations where you want to include contents in your project from an\n+independently developed project. You can just pull from the other project as\n+long as there are no conflicting paths.\n+\n+The problematic case is when there are conflicting files. Potential candidates\n+are Makefiles and other standard filenames. You could merge these files but\n+probably you do not want.  A better solution for this problem can be to merge\n+the project to its own subdirectory. This is not supported by the 'recursive'\n+merge strategy, so just pulling won't work.\n+\n+What you want is the 'subtree' merge strategy, which helps you in such a\n+situation.\n+\n+In this example, let's say you have the repository at `/path/to/B` (but it can\n+be an URL as well, if you want). You want to merge the 'master' branch of that\n+repository to the `dir-B` subdirectory in your current branch.\n+\n+Here are all the commands you need:\n+\n+----------------\n+$ git remote add -f Bproject /path/to/B <1>\n+$ git merge -s ours --no-commit Bproject/master <2>\n+$ git read-tree --prefix=dir-B/ -u Bproject/master <3>\n+$ git commit -m \"Merge B project as our subdirectory\" <4>\n+\n+$ git pull -s subtree Bproject master <5>\n+----------------\n+<1> name the other project \"Bproject\", and fetch.\n+<2> prepare for the later step to record the result as a merge.\n+<3> read \"master\" branch of Bproject to the subdirectory \"dir-B\".\n+<4> record the merge result.\n+<5> maintain the result with subsequent merges using \"subtree\"\n+\n+The first four commands are necessary for the initial merge, while the last one\n+should be used to merge updates from 'B project'.\n+\n+Comparing 'subtree' merge with submodules\n+-----------------------------------------\n+\n+- The benefit of using subtree merge is that it requires less attention from\n+  the users of your repository. It works with older (before Git v1.5.2) clients\n+  and you have the code right after clone.\n+\n+- However if you use submodules then you can choose not to transfer the\n+  submodule objects. This may be a problem with the subtree merge.\n+\n+- Also, in case you make changes to the other project, it is easier to submit\n+  changes if you just use submodules.\n+\n+Additional tips\n+---------------\n+\n+- If you made changes to the other project in your repository, they may want to\n+  merge from your project. This is possible using subtree -- it can shift up\n+  the paths in your tree and then they can merge only the relevant parts of\n+  your tree.\n+\n+- Please note that if the other project merges from you, then it will connects\n+  its history to yours, which can be something they don't want to.\n-- \n1.5.4.rc2-dirty\n"}]}