Eric O. Lebigot
Eric O. Lebigot

Reputation: 94595

How to add a sequence of commits to another branch?

In git, how to apply the sequence of commits "D-E"

master       A-B
                \
py3-version      C-D-…-E

back onto master, so as to obtain

master       A-B - <D patch applied> - <…> - <E patch applied>
                \
py3-version      C-D-…-E

I want to do this because master is a Python 2 version, with C being a Python 3 version generated automatically (through 2to3), that I needed to improve (D to E). Now, I would like to put back improvements D to E onto the master branch (and eventually forget about C and the py3-version, which will be regenerated from the new master branch). How can this be done?

Upvotes: 1

Views: 108

Answers (1)

uml&#228;ute
uml&#228;ute

Reputation: 31374

this is called cherry-picking in git lingo, where you can import changes selectively from one branch into another:

git checkout master
git cherry-pick py3-version~10..py3-version

this will pick the last 10 commits from the "py3-version" branch.

In case of conflicts you are prompted to manually resolve them. Then you should continue the cherry-picking with git cherry-pick --continue (or git cherry-pick --abort, if something went wrong).

Upvotes: 3

Related Questions