[plug] Merging 2 files, CVS-style

Nick Bannon nick at ucc.gu.uwa.edu.au
Thu Apr 13 12:37:28 WST 2000


On Thu, Apr 13, 2000 at 11:04:36AM +0800, Peter Wright wrote:
[...]
> I'm working on a software project using CVS for version control, which
> I'm guessing at least a few of you should be familiar with. Now CVS
> has a very nice conflict-resolution merging facility - when you've
> changed an old revision of a file and then try to update it, it marks
[...]

I think your problem is tricky - the way CVS works is that it has _three_
files to compare - two plus a common ancestor. If the ancestor and
version 1 differ, it'll merge it in. If the ancestor and version 2
differ, it'll merge it in. If all three differ, it's a conflict.

Using RCS (which CVS is built on), the following seems to work.

First, make a common "ancestor" - if your files are less than 999 lines
long, perhaps you could use "diff -u999 version1 version2 > ancestor",
then cut out everything but the matching lines, and then the first column
with "cut -c2-". Maybe "comm" or something like it can do this in a more
straightforward manner.

Then check them in to RCS one after the other - it'll generate a different
version number for each. The -t's and -m's are just to suppress it asking
for log messages. This should work ;

mermaid: /tmp>cat ancestor > n; ci -t-test n;co -l n
n,v  <--  n
initial revision: 1.1
done
n,v  -->  n
revision 1.1 (locked)
done
mermaid: /tmp>cat version1 > n; ci -mtest1 n;co -l n
n,v  <--  n
new revision: 1.2; previous revision: 1.1
done
n,v  -->  n
revision 1.2 (locked)
done
mermaid: /tmp>cat version2 > n; rcsmerge -r1.1 -r1.2 n
RCS file: n,v
retrieving revision 1.1
retrieving revision 1.2
Merging differences between 1.1 and 1.2 into n
rcsmerge: warning: conflicts during merge

"n" should now be your newly merged file, with "<<<<<<" marked conflict
sections.

There's an RCS tutorial at ;
http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/rcs/

and an "rcsintro" man page.

Nick.

-- 
  Nick Bannon  | "I made this letter longer than usual because
nick at it.net.au | I lack the time to make it shorter." - Pascal



More information about the plug mailing list