Arkadiy Arkadiy - 1 year ago 48
Git Question

git: Merge newer branch into older branch without picking trunk chnages

I have a situation where code developed in a branch off master (FEATURE) needs to be merged into an older branch RELEASE (and then released as part of a release from that older branch).

\ \
\ \-X-Y-Z->(FEATURE)

If I simply say
git merge FEATURE
on the RELEASE branch, I'll pick up commits 4,5,6 - and I don't want them.

I'd rather not do cherry-picking as the FEATURE has 80+ commits, each potentially conflict-prone.

Is there a way to just merge X,Y,Z into RELEASE?

Answer Source

Create a new branch feature_to_be_merged based on feature. Rebase it on commit 3 and merge it onto release.

Beware that the rebase operation might lead to conflicts.