You are right that you want to take advantage of the git merge faculties. There are a few more options. The most indicative of what actually happened is probably a merge, but the method leading to a modified version of E applied on top of D is also not so bad. Tell us how to do it!
If the patch contains the blob to which it belongs (the output from git format-patch does), then git am is able to perform a three-way merge! The diff blob SHA1 entries look like this:
diff
If you have it, you're in luck. Just use git am --3way <patch> . Unfortunately, git am requires an email-style header that creates a format patch, so if the patch came from git diff instead of git format-patch , you need to get a little confused. You can add it yourself:
From: Bobby Tables <bobby@drop.org> Date: 2 Nov 2010 Subject: [PATCH] protect against injection attack <original diff>
git am should work with this, and if you don’t get everything exactly how you wanted it, you can always git commit --amend fix it. (You can also try using git apply --build-fake-ancestor=foo.txt <patch> , but that really doesn't work in a friendly way. I think git am trickster is easier.)
If the patch does not contain any bla SHA1 (i.e. it was created using the diff command, not the git command), tell your friend again how to use git, and I'm sure you can still put it off. You know which version of foo.txt the patch should use! To get SHA1 from commit B, use:
git ls-tree <SHA1 of B>:<directory containing foo.txt>
This will be one of the given drops. (I know there is a direct path, but I just can't think about it right now.) Then you can add a fake git diff header. Suppose its hash is abcdef12:
diff
Git doesn't really need anything except the first hash; although git diff output would have a final hash and mode, am does not look for it, so you can leave by leaving it. (And yes, I just checked it. I haven’t done this before!)
This will lead to a story like A - B - C - D - E' , where E' is your patch for a friend, but applies to D ; this is the result of a three-way merge between the contents in D , B and your friend's patch.
Finally, if you do not want to cheat any of this, you can do as you said:
git checkout -b bobby <SHA1 of B>