I want to take advantage of the git-merge algorithm on two arbitrary files in a git repo. Here is my working directory:
folder/
file1
file2
file1 and file2 are similar, but I want to see how git would merge them as if they were different versions of the same file. In other words, I want something like this:
git merge-files file1 file2 > merge_of_file1_file2
Is there a way to do this?
This doesn’t really make sense, because you’re not providing a common ancestor. If you do have one, however, you can use:
This places the results in the current version file; if you want them elsewhere, use:
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: