Requirement:
- There are two repositories
- There are common file between these two repositories
- An older one, lets call it as parent
- The newest one, lets call it as child
- We want to apply all changes from child to parent
- There are no common ancestor between child and parent
Problem Statement:
The simplest way would be to fork the child repository into parent repository and issue:
git merge child_repo/master
However, as there is no common ancestor, git will reject this merge.
Another option is to then add --allow-unrelated-histories option to merge.
git merge child_repo/master --allow-unrelated-histories
However, this results into merge-conflicts
Workaround:
Identify which all commits are to be taken from child to parent. e.g.
git rev-list child_repo/master
e.g. there are 3 commits in child_repo/master and except the first commit in child_repo/master every change is needed and to be applied on top of parent, then issue following command.
git rev-list child_repo/child --reverse --max-count=2 | git cherry-pick --stdin
This will reverse the commit order of child_repo/master and apply one-by-one to parent.
Visualization:
Before:
child: [c0]---[c1]---[c2]
parent:[p1]---[p2]---[p3]---[p4]
After:
child: [c0]---[c1]---[c2]
parent:[p1]---[p2]---[p3]---[p4]---[c1']--[c2']
Preparation thoughts:
The repositories can be locally forked, e.g. directories for parent and child
parent: c:\git\parent\.git
child: c:\git\child\.git
Now, open git-bash at parent and issue following command:
git remote add child_repo ..\child\.git
and get latest commits from child as:
git pull child_repo
Comments
Post a Comment