Jay
Jay

Reputation: 1038

Git merge starting from certain commit of the feature branch

If I have the following git branches

master: A - B - C - DE
         \
topic:    \- D - E - F - G

Is there any way to merge commit F and G to master?

The reason I want to do this is that I've already done a pull request from topic to master before I made commit F and commit G to merge D and E to after C. I did a squash and merge so now DE contains the merge of D and E. Now I need merge only F and G to master.

Upvotes: 2

Views: 492

Answers (1)

eftshift0
eftshift0

Reputation: 30156

You can do:

git rebase --onto master E topic

You are asking git to rebase topic branch on top of master discarding revisions up to E (so, basically asking to carry over F and G only).

Results:

master: A - B - C - DE
                     \
topic:                F' - G'

Then you could merge into master

git checkout master
git merge topic

Or have the branch move instead:

git branch -f master topic

Alternatively, you could cherry-pick into master:

git checkout master
git cherry-pick topic~2..topic # bring over the last 2 revisions from topic into master

Upvotes: 2

Related Questions