icedwater
icedwater

Reputation: 4887

Merging selected files from similar branches after one was rebased

While I was working on feature1, at commit point A below, I was asked to build another mod onto it. Let's call it feature1+. This means the graph looks like this:

master: o---o---o---o---o
             \
feature1:     o---e---e---e---O---A
                                   \
feature1+:                          o---c---c---X

Now I want to merge feature1+ back onto feature1, but I realise the changes between files existing at X and A are minimal; there are two new tracked files in the c commits.

Along the way, I began consolidating the commits on feature1, rebasing the e commits into a single one o' to reduce the number of commits back on master in the end. I believe the effective graph is this:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A
               \     
feature1+:      o---e---e---e---O---A---c---c---X

However, this means feature1+ dumps the e commits onto feature1 as well when I run:

git checkout feature1
git merge feature1+

Which gives me:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A---e---e---e---O---c---c---X

I want to add the c commits without reintroducing the e ones. In other words, merge it back into this:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A---c---c---X

How may I do so? I've tried to just checkout the new files from c when in feature1 at A, but of course this gives the files without retaining their history.

Upvotes: 3

Views: 38

Answers (2)

Grant Diffey
Grant Diffey

Reputation: 56

While on branch: feature1 checked out at A:

doing git cherry-pick feature1+: A .. X should result in the desired tree

master: o---o---o---o---o
             \
feature1:     o---o'---O---A---c---c---X

Upvotes: 3

icedwater
icedwater

Reputation: 4887

The shortest answer, suggested by @nevyn on the #git channel in Freenode IRC, was to cherry-pick the desired commits onto feature1 (the docs suggested this but I was probably just afraid to try):

git checkout feature1
git cherry-pick c # the first c
git cherry-pick c # OK, the second one, I didn't think ahead THAT far.
git branch -d feature1+ # warns + gives the correct command for an unmerged branch

Upvotes: 0

Related Questions