{"id":5563,"date":"2004-06-14T17:12:00","date_gmt":"2004-06-14T17:12:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/buckh\/2004\/06\/14\/a-simple-example-using-branch-and-merge\/"},"modified":"2004-06-14T17:12:00","modified_gmt":"2004-06-14T17:12:00","slug":"a-simple-example-using-branch-and-merge","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/buckh\/a-simple-example-using-branch-and-merge\/","title":{"rendered":"A simple example using branch and merge"},"content":{"rendered":"<p><P>Merge is an overloaded word. There is a content merge and then there is a branch merge. A content merge is where you have edited a file and someone checked in a newer file, so the source control system will tell you to do a content merge before checking in the file (if it&#8217;s interactive, it&#8217;s a 3-way merge GUI). \n<P>A branch merge is migrating changes from one branch to another. If a source branch A has a file rock.cs that had been edited and file scissors.cs that had been deleted, merging these changes into a target branch B would result in a pending edit on file rock.cs and a pending delete on the file scissors.cs in the target. \n<P>Here&#8217;s a simple&nbsp;example that uses the command line.&nbsp; The biggest differences between this and a &#8220;real-world&#8220; example are the number of files involved (you may have thousands) and that you would probably have conflicts for a subset of the files (e.g., the same file was edited both in the source and in the target, resulting in the need to do a 3-way content merge).\n<P>The \/i option is the shortcut for the &#8220;noprompt&#8221; option that makes everything non-interactive, as would be needed in batch script. Changes are committed in change sets, and the whole check in either succeeds or fails (it&#8217;s atomic). \n<P>1. Create a workspace and add the files mentioned in the merge explanation above. \n<BLOCKQUOTE><PRE>D:\\project&gt;h workspace \/i \/new MyProject<\/p>\n<p>D:\\project&gt;h add \/r A\nA<\/p>\n<p>A:\nrock.cs\nscissors.cs<\/p>\n<p>D:\\project&gt;h checkin \/i\nadd A<\/p>\n<p>A:\nadd rock.cs\nadd scissors.cs\nChange set #4 checked in.\n<\/PRE><\/BLOCKQUOTE>2. Create a branch from A to a target B. \n<BLOCKQUOTE><PRE>D:\\project&gt;h branch A B\nB<\/p>\n<p>B:\nrock.cs\nscissors.cs<\/p>\n<p>D:\\project&gt;h checkin \/i\nbranch B<\/p>\n<p>B:\nbranch rock.cs\nbranch scissors.cs\nChange set #5 checked in.\n<\/PRE><\/BLOCKQUOTE>3. Now we have A and B in the repository, related by B being a branch of A. \n<BLOCKQUOTE><PRE>D:\\project&gt;h dir \/r\n$\/:\n$A\n$B<\/p>\n<p>$\/A:\nrock.cs\nscissors.cs<\/p>\n<p>$\/B:\nrock.cs\nscissors.cs<\/p>\n<p>6 item(s)\n<\/PRE><\/BLOCKQUOTE>4. The branches command shows that B is branched from A. \n<BLOCKQUOTE><PRE>D:\\project&gt;h branches A\n&gt;&gt; $\/A &lt;&lt;\n     $\/B Branched from version 1\n<\/PRE><\/BLOCKQUOTE>5. Now we edit rock.cs and delete scissors.cs in the source branch. \n<BLOCKQUOTE><PRE>D:\\project&gt;h edit A\\rock.cs\nA:\nrock.cs<\/p>\n<p>D:\\project&gt;echo new line &gt;&gt; A\\rock.cs<\/p>\n<p>D:\\project&gt;h delete A\\scissors.cs\nA:\nscissors.cs<\/p>\n<p>D:\\project&gt;h checkin \/i\nA:\nedit rock.cs\ndelete scissors.cs\nChange set #6 checked in.\n<\/PRE><\/BLOCKQUOTE>6. Merge the changes made in branch A over to branch B. Of course in a real project, there may be conflicts to resolve (rock.cs may have been edited both in the source and target, which will need to be merged with a 3-way content merge), and the developer may need to make additional changes in B (for example, B may be a newer release of the project and the code may be need to be changed due to an API change made earlier in B). \n<BLOCKQUOTE><PRE>D:\\project&gt;h merge A B\nmerge, edit: $\/A\/rock.cs;C5~C6 -&gt; $\/B\/rock.cs;C5\nmerge, delete: $\/A\/scissors.cs;C5~C6 -&gt; $\/B\/scissors.cs;C5<\/p>\n<p>D:\\project&gt;h checkin \/i\nB:\nmerge, edit rock.cs\nmerge, delete scissors.cs\nChange set #7 checked in.\n<\/PRE><\/BLOCKQUOTE>6. In the history, we see that B\\rock.cs was created by branching in change set 5 and then an edit was merged in change set 7. \n<BLOCKQUOTE><PRE>D:\\project&gt;h history \/i B\\rock.cs\nVers Date       Chngset User          Change Type          Files\n&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\n   2 06\/14\/2004       7 buckh         merge, edit          $\/B\/rock.cs\n   1 06\/14\/2004       5 buckh         branch               $\/B\/rock.cs\n<\/PRE><\/BLOCKQUOTE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merge is an overloaded word. There is a content merge and then there is a branch merge. A content merge is where you have edited a file and someone checked in a newer file, so the source control system will tell you to do a content merge before checking in the file (if it&#8217;s interactive, [&hellip;]<\/p>\n","protected":false},"author":94,"featured_media":10268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6],"class_list":["post-5563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-source-control"],"acf":[],"blog_post_summary":"<p>Merge is an overloaded word. There is a content merge and then there is a branch merge. A content merge is where you have edited a file and someone checked in a newer file, so the source control system will tell you to do a content merge before checking in the file (if it&#8217;s interactive, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/5563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/comments?post=5563"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/5563\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media\/10268"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media?parent=5563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/categories?post=5563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/tags?post=5563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}