Ed Avis
Ed Avis

Reputation: 1502

Three-way merge of files (outside version control)

I have three versions of a file: the original, my changes, and someone else's changes. I would like to do a three-way merge to produce a version incorporating both sets of changes (or fail if this is not possible). Note that I am not asking about any revision control system such as svn or git. I would like to write a minimal command-line tool which takes the three files as input and writes the merge to standard output.

One way is as follows, using the Unix diff and patch tools. Assuming the three files are called orig, my, other:

% diff -u orig my | patch -o - other

or doing it the other way round,

% diff -u orig other | patch -o - my

But the fact that there are two ways round to do the diff and merge is something of a code smell. Surely a merge tool that takes all three files as input could do a better job.

Obviously I could initialize an empty svn repository, check in orig, check in my and other in separate branches, and then do a merge. Or the equivalent operation in another version control system. But that seems heavyweight and clunky, creating a repository which will be thrown away immediately.

Is there a reasonable three-way merge tool which runs standalone from the command line?

Upvotes: 2

Views: 378

Answers (1)

Ed Avis
Ed Avis

Reputation: 1502

As twalberg said in a comment, merge is the tool I was looking for.

Upvotes: 0

Related Questions