vbem vbem - 4 months ago 8
Git Question

In Git, how to merge (not checkout) part of files from a long ago branch

Like Fig.A,

release-1.0
is delivered to customer long long ago, but a huge bug was found recently, and a hotfix is made in
release-1.1
and re-delivered.

Now I would like to merge only bugfix files (about 10 files) from
release-1.1
into branch
master
in
Fig.B
way, that is,
release-1.1
must be a parent-node of
master
in git history. So
git checkout release-1.1 <file>
way does not match this purpose.

Meanwhile, since
c2
is so far from
master
, there are too many different files (nearly hundreds files that can not merge automatically), and the work of canceling these merge conflicts may kill me....

So how could I realize this purpose in git? Sorry for my poor English and poor git skills. ^_^

Fig A:

release-1.0 <--- release-1.1
|
v
c1 <--- c2 <--- c3 <--- c4 <--- c5 <--- c6 <--- master


Fig B:

release-1.0 <--- release-1.1 <----------------------\
| |
v |
c1 <--- c2 <--- c3 <--- c4 <--- c5 <--- c6 <--- c7 <--- master

Answer

I don't see any way around dealing with potential merge conflicts, because the hotfix was made on a much older version of the branch.

One option would be to cherry-pick the hotfix commit, and then choose the version of the files from the latest master branch for all files except for the 10 files involved in the hotfix:

git checkout master
git cherry-pick <SHA-1 release-1.1>

where <SHA-1 release 1.1> is the SHA-1 hash of the hotfix commit in the release-1.1 branch. Keep in mind you may get conflicts in the 10 hotfix files themselves. In this case, you should focus on the hotfix changes, tending to choose the latest master version in all other cases.

Comments