Reputation: 1073
Our codebase imports files from a different codebase, and modifies them to fit in our codebase. We can't share the history of the codebases, for practical reasons (that are irrelevant to the question).
How can I perform a 3-way merge of imported files? Where:
I'd preferably use git to perform this merge, to avoid depending on an external tool, but git is deeply tied to a shared history that doesn't exist in this case, and I don't know how to coerce git into doing the merge given just the files and no history.
Upvotes: 0
Views: 77
Reputation: 45649
You can do this on a file-by-file basis with git merge-file
(https://git-scm.com/docs/git-merge-file). If there are many files involved, this could be quite tedious.
Alternately, you could create temporary "integration repos" in which to do the merge.
mkdir merge-repo
cd merge-repo
git init
# copy in the previous imported version of each file
git add .
git commit -m base
git branch source
# copy in the current version of each file with your changes (note you're still on master)
git add .
git commit -m ours
git checkout source
# copy in the current version of each file from the source repo
git add .
git commit -m theirs
git checkout master
git merge source
# copy the merged files back to your repo
cd ..
rm -rf merge-repo #if you don't want to keep it around, you don't need it any more
The latter may have more moving parts, but I bet you could script them and it'll be a lot less tedious than going file by file to stage up individual merge-file
commands.
Upvotes: 3