Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Please see the <a href="https://stackoverflow.com/a/26012910/110204">answer below</a> by Magras de La Mancha for better solution with Mercurial 3.1.</em> The below is a simpler and more naive solution for older versions of Mercurial.</p> <hr> <p>Yes, you need to configure a custom <a href="https://www.mercurial-scm.org/wiki/MergeToolConfiguration" rel="nofollow noreferrer">merge tool</a> for your <code>.hgtags</code> file. Mercurial doesn't provide any special merge tool for <code>.hgtags</code>, you're expected to merge it by hand using your normal three-way merge tool.</p> <p>Conflicts in the <code>.hgtags</code> file can have two types:</p> <ul> <li><p><strong>Silly conflicts:</strong> This is the situation you have and there is not really a conflict here. What happens is that one branch has</p> <pre><code>f40273b0ad7b3a6d3012fd37736d0611f41ecf54 A 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 B 12e0fdbc57a0be78f0e817fd1d170a3615cd35da C </code></pre> <p>and the other branch has</p> <pre><code>f40273b0ad7b3a6d3012fd37736d0611f41ecf54 A 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 B 979c049974485125e1f9357f6bbe9c1b548a64c3 D </code></pre> <p>Each tag refers to exactly one changeset, so there's no conflict here. The merge should of course be the <em>union</em> on of the two files:</p> <pre><code>f40273b0ad7b3a6d3012fd37736d0611f41ecf54 A 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 B 12e0fdbc57a0be78f0e817fd1d170a3615cd35da C 979c049974485125e1f9357f6bbe9c1b548a64c3 D </code></pre></li> <li><p><strong>Real conflicts:</strong> There one branch has</p> <pre><code>f40273b0ad7b3a6d3012fd37736d0611f41ecf54 A 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 B 12e0fdbc57a0be78f0e817fd1d170a3615cd35da C </code></pre> <p>and the other branch has</p> <pre><code>f40273b0ad7b3a6d3012fd37736d0611f41ecf54 A 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 B 979c049974485125e1f9357f6bbe9c1b548a64c3 C </code></pre> <p>There is a real conflict here: <code>hg tag C</code> was done on both branches, but the tags refer to different changesets. Resolving this is a manual task.</p></li> </ul> <p>If you can guarantee that you'll only have <em>silly conflicts</em> and that you only have one tag per changeset, then you can use</p> <pre><code>hg log -r "tagged()" --template "{node} {tags}\n" &gt; .hgtags </code></pre> <p>to generate a new <code>.hgtags</code> file. The key insight is that Mercurial <strong>knows how to merge tags</strong> internally! It does this all the time when you have two heads with different <code>.hgtags</code> files. The above template simply generates a new <code>.hgtags</code> file based on this internal merge.</p> <p>If you might have more than one tag per changeset, then the above wont work — all the tags are printed on one line so you get a tag <code>foo bar</code> instead of two tags <code>foo</code> and <code>bar</code>. You can then use this <a href="http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html" rel="nofollow noreferrer">style file</a> instead:</p> <pre><code>changeset = "{tags}" tag = "{node} {tag}\n" </code></pre> <p>It outputs one line per <em>tag</em>, not changeset. You save this style somewhere and configure a merge tool:</p> <pre><code>[merge-tools] hgtags.executable = hg hgtags.args = log -r "tagged()" --style ~/tmp/tags-style &gt; $output hgtags.premerge = False hgtags.priority = -1000 [merge-patterns] .hgtags = hgtags </code></pre> <p>You now have automatic tag merges. There are some caveats:</p> <ol> <li><p><strong>Three or more heads:</strong> The technique only works if you have <strong>two heads</strong> at the time of merging. If you have three heads or more, it's possible for a deleted tag to re-appear. If you have heads X, Y, and Z, and the tag <code>A</code> is deleted in X, then Mercurial is normally able to figure out that <code>A</code> is deleted overall. It does this based on a <code>000...0 A</code> line in the <code>.hgtags</code> file in X. However, if you merge X and Y to get W, then the approach suggested will not contain any such <code>000...0 A</code> line. The definition of <code>A</code> from Z will now suddenly take effect and re-introduce <code>A</code>.</p></li> <li><p><strong>Real conflicts:</strong> If you have real conflicts in <code>.hgtags</code>, then the above method will <strong>silently pick the tag from the most recent head</strong> for you. The merge tool basically saves <code>hg tags</code> in <code>.hgtags</code>, and the behavior of <code>hg tags</code> with multiple heads is <a href="https://www.mercurial-scm.org/wiki/Tag#How_do_tags_work_with_multiple_heads.3F" rel="nofollow noreferrer">explained in the wiki</a>. Since <code>hg tags</code> unconditionally reads and silently merges the <code>.hgtags</code> file from all heads, there's nothing we can do about it with this simple approach. Dealing with this would require a bigger script that reads the two <code>.hgtags</code> files and detects the conflict.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload