run git merge algorithm on two individual files

For what you are trying to do:

touch file3  #empty
git merge-file file1 file3 file2

This will do a three-way merge of file1 and file2 with file3 ( empty file ) as the base.

Note that this writes to file1. You can of course do the below if that is not desired:

touch file3
cp file1 merge_of_file1_file2
git merge-file merge_of_file1_file2 file3 file2

This doesn't really make sense, because you're not providing a common ancestor. If you do have one, however, you can use:

git merge-file <current-version> <common-ancestor> <other-version>

This places the results in the current version file; if you want them elsewhere, use:

git merge-file -p <current> <common> <other> > <dest>

It needs the common ancestor to provide something to consider changes relative to. You could hack it, by providing an empty file or a copy of an older version of one of them from the history of your repository, but the quality of results will depend on how well you select a common ancestor, since it's merging the two diffs, between that and each of the new versions. An empty file will only work well if the two are very similar (many runs of at least three identical lines).

Without that, all you can really do is look at the differences:

git diff --no-index file1 file2

Tags:

Git