Reputation: 22984
How to apply the same changes (in several commits) to different branches?
First of all, this is different from How to copy commits from one branch to another? as the purpose is different, thus the answer there was specific for that question.
I've got a project that has a master branch and a stable branch - the branches diverged long time ago. Now I need to backport a fix to that stable release branch -- I've got a couple commits on the master branch, which I also want to have on the stable branch (a bug fix). I cannot merge, as the branches diverged and there's loads of unmerged changes - I just want my 8 commits.
Actually the answer from How to cherry pick a range of commits and merge into another branch? is more close to what I'm looking for,
However that answer begins with:
When it comes to a range of commits, cherry-picking was not practical.
and didn't give clear git
command for people to follow.
UPDATE: The proposed answer GIT cherry pick all my commits that exists in one branch to another branch does not solve my problem as I've explained in the comment right away -- that question, "I want to cherry pick all commits that doesn't already exist in branch A from branch B to branch A without the need to manually search for every single one", is different than what I'm asking here.
Upvotes: 0
Views: 412
Reputation: 141986
When it comes to a range of commits, cherry-picking was not practical.
The "problem", if you can call it so, is that if you wish to pick several commits and they are in sequence its an excellent solution.
But if you wish to exclude several commits you will need to cherry-pick
them in segments.
For example:
Given the following commits: 1-2-3-4-5-6-7-8-9
if you wish to cherry-pick
1-3
and 5-7
you have to break it into segments:
git cherry-pick 1.. 3 5..7
So what's clear git command that cherry pick the range of my commits?
The above command.
# (2 dotes) Pick all commits in the range from a to be
git cherry-pick a..b
# (3 dotes) pick all commits which are not in both branches
git cherry-pick a...b
# pick a single commit
git cherry-pick a
# pick commit range(s)
git cherry-pick 1..3 5 6 7
Upvotes: 2