Consider 2 unrelated (no common commits) repositories (and histories), in dirs a
and b
.
$ cd b
$ git remote add a ../a
$ git fetch a
$ git --no-pager log --oneline --graph --all
* 4b68cfa (HEAD -> master) 11,2,3
* 79591c1 (a/master) 3 -> 33
* 6a41c8b 1,2,3
Repository a
, file f
, commit 6a41c8b
:
1
2
3
The following commit (79591c1
) changes 3
to 33
.
Repository b
, file f
, commit 4b68cfa
(a root node that starts a separate branch):
11
2
3
Cherry-picking or rebasing 3 -> 33
onto 11,2,3
succeeds. Merging of the 2 branches/repositories fails. (proof)
format-patch
+ am
succeeds provided that you have commits from both repositories/branches (1):
$ cd b
$ git remote add a ../a
$ git fetch a
and that you supply -3
to git am
(2). (proof)
So it does within a single repository (copying 3 -> 33
onto 1 -> 11
):
* 9987dd0 (dev) 3 -> 33
| * dcd467c (HEAD -> master) 1 -> 11
|/
* a56b04a 1,2,3
The first precondition is met automatically, the second one is still needed. (proof)