0

I just learned how to do octopus merges in GitHub.

I'm working with a system where we create a patchwork of patches using a common ancestor. We'll call common ancestor VersionA. VersionB and VersionC are branched and modified from VersionA. I would like to derive two patches: VersionAB and VersionAC.

Using git, I can do a

git branch 3Way VersionA
git checkout 3Way
git merge VersionB and VersionC

gives me a VersionABC

As long as the common ancestor is setup correctly, the resulting files are auto-merged using the git <<<< and ==== and >>>> methods.

Is there a way I can apply the same setup/logic but using patch files? I think I can derive patch files from the git 'octopusmerge', but the only way I got to the octopusmerge of the mods was via git. Is there a way to arrive at VersionABC using source files of the branches, and then try to derive a VersionABC from the patch files?

We wanted to include a tool where we work with raw data, extract patch file differences from various mods that are branches of VersionA, then combine those patch files somehow in a manner where we'd be able to achieve VersionABC.

Closest answer I have is interdiff, but if that's my answer. How do I setup my environment (aka, what steps and in what order, and in what way do I run the patch and interdiff commands?)

1 Answer 1

1

The command for that is:

git apply --3way patchfile1.patch patchfile2.patch...

When git exports a patch file with git diff something..HEAD it records what revision something means. This revision is the common ancestor. git apply --3way looks at the recorded revision and does a three way merge with the current HEAD, the common ancestor, and the new HEAD that the patch would create if applied to the common ancestor.

It goes through this process for every patch file listed on the command line.

If you want to do this without git, that is much harder. Since there isn't a widely known way to do this without a VCS. The obvious way to do that would be similar to an octopus merge is to just use:

cat patchfile1.patch patchfile2.patch... | patch --merge -p1

Otherwise, a 3-way merge is probably going to require the source directories of each version and then in a shell script:

mkdir VersionABC
for i in (cd VersionA && ls -R); do
  if [ -f VersionA/$i ]; then
    diff3 --merge VersionB/$i VersionA/$i VersionC/$i > VersionABC/$i
  else
    mkdir -p VersionABC/$i
  fi
done
4
  • 1
    what does that command do? Apply two patches to a git checked out branch in a 3way merge? That wasn't my question exactly. But how something like this can be done OUTSIDE of Git. I do appreciate the feedback though as I didn't know how to use patches in git in this manner. Aug 20, 2014 at 15:56
  • @thistleknot The new shell script should work so long as there are no new files. Aug 20, 2014 at 16:57
  • "Otherwise, a 3-way merge is probably going to require the source directories of each version and then in a shell script:" This is the thinking we had. We would carry forward our patch files, and derive folders based on our patch files... am I reading that right, "VersionB/$i VersionA/$i VersionC/$i" Blood Alcohol Content? lol. Not ABC? Aug 21, 2014 at 0:46
  • I think diff3 is what I've been looking for. Aug 21, 2014 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.