<div id="Merging-and-keywords"></div>
<div class="header">
<p>
Previous: [[cvs: Merging can add or remove files#Merging can add or remove files|Merging adds and removals]], Up: [[cvs: Branching and merging#Branching and merging|Branching and merging]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>

----

<div id="Merging-and-keywords-1"></div>
=== Merging and keywords ===
<div id="index-Merging_002c-and-keyword-substitution"></div>
<div id="index-Keyword-substitution_002c-and-merging"></div>
<div id="index-_002dj-_0028merging-branches_0029_002c-and-keyword-substitution"></div>
<div id="index-_002dkk_002c-to-avoid-conflicts-during-a-merge"></div>

If you merge files containing keywords (see [[cvs: Keyword substitution#Keyword substitution|Keyword substitution]]), you will normally get numerous
conflicts during the merge, because the keywords are
expanded differently in the revisions which you are
merging.

Therefore, you will often want to specify the
&lsquo;<code>-kk</code>&rsquo; (see [[cvs: Substitution modes#Substitution modes|Substitution modes]]) switch to the
merge command line.  By substituting just the name of
the keyword, not the expanded value of that keyword,
this option ensures that the revisions which you are
merging will be the same as each other, and avoid
spurious conflicts.

For example, suppose you have a file like this:

<div class="example" style="margin-left: 3.2em">
        +---------+
       _! 1.1.2.1 !   &lt;-  br1
      / +---------+
     /
    /
 +-----+    +-----+
 ! 1.1 !----! 1.2 !
 +-----+    +-----+
</div>

and your working directory is currently on the trunk
(revision 1.2).  Then you might get the following
results from a merge:

<div class="example" style="margin-left: 3.2em">
 $ cat file1
 key $<i></i>Revision: 1.2 $
 . . .
 $ cvs update -j br1
 U file1
 RCS file: /cvsroot/first-dir/file1,v
 retrieving revision 1.1
 retrieving revision 1.1.2.1
 Merging differences between 1.1 and 1.1.2.1 into file1
 rcsmerge: warning: conflicts during merge
 $ cat file1
 &lt;&lt;&lt;&lt;&lt;&lt;&lt; file1
 key $<i></i>Revision: 1.2 $
 =======
 key $<i></i>Revision: 1.1.2.1 $
 &gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.1.2.1
 . . .
</div>

What happened was that the merge tried to merge the
differences between 1.1 and 1.1.2.1 into your working
directory.  So, since the keyword changed from
<code>Revision: 1.1</code> to <code>Revision: 1.1.2.1</code>,
<small>CVS</small> tried to merge that change into your working
directory, which conflicted with the fact that your
working directory had contained <code>Revision: 1.2</code>.

Here is what happens if you had used &lsquo;<code>-kk</code>&rsquo;:

<div class="example" style="margin-left: 3.2em">
 $ cat file1
 key $<i></i>Revision: 1.2 $
 . . .
 $ cvs update -kk -j br1
 U file1
 RCS file: /cvsroot/first-dir/file1,v
 retrieving revision 1.1
 retrieving revision 1.1.2.1
 Merging differences between 1.1 and 1.1.2.1 into file1
 $ cat file1
 key $<i></i>Revision$
 . . .
</div>

What is going on here is that revision 1.1 and 1.1.2.1
both expand as plain <code>Revision</code>, and therefore
merging the changes between them into the working
directory need not change anything.  Therefore, there
is no conflict.

'''WARNING: In versions of <small>CVS</small> prior to 1.12.2, there was a
major problem with using &lsquo;<code>-kk</code>&rsquo; on merges.  Namely, &lsquo;<code>-kk</code>&rsquo;
overrode any default keyword expansion mode set in the archive file in
the repository.  This could, unfortunately for some users, cause data
corruption in binary files (with a default keyword expansion mode set
to &lsquo;<code>-kb</code>&rsquo;).  Therefore, when a repository contained binary files,
conflicts had to be dealt with manually rather than using &lsquo;<code>-kk</code>&rsquo; in
a merge command.'''

In <small>CVS</small> version 1.12.2 and later, the keyword expansion mode
provided on the command line to any <small>CVS</small> command no longer
overrides the &lsquo;<code>-kb</code>&rsquo; keyword expansion mode setting for binary
files, though it will still override other default keyword expansion
modes.  You can now safely merge using &lsquo;<code>-kk</code>&rsquo; to avoid spurious conflicts
on lines containing RCS keywords, even when your repository contains
binary files.


----

<div class="header">
<p>
Previous: [[cvs: Merging can add or remove files#Merging can add or remove files|Merging adds and removals]], Up: [[cvs: Branching and merging#Branching and merging|Branching and merging]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>
This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
