Say I have made a bunch of changes in master. But, I want to cherrypick all the ones not in branch:release-5 onto to it.
-
Why don’t you just merge master into your branch? – poke May 09 '14 at 17:12
-
1Don't ask ... I ask myself the same question. But, besides the point. – smartnut007 May 09 '14 at 17:13
-
Just cherry-pick them all, unless memory is playing nasssty tricks on me any that are already applied will be ignored. – jthill May 09 '14 at 18:40
2 Answers
You can cherry pick, but it would be much easier if you rebase:
git checkout -b missing-commits master
git rebase -i --author=me release-5
All the commits already in release-5 won't be picked, and only your commits will. Afterwards you can merge the branch missing-commits into release-5.
That being said you can use cherry-pick:
git cherry-pick --skip-empty --cherry-pick --no-merges --right-only --topo-order --do-walk master...release-5
As you can see it's much easier to use git rebase
, which interally does the cherry-picking for you.

- 9,123
- 4
- 44
- 38
-
2I didn't find any options for `cherry-pick --skip-empty`, is that any wrong here? – William Leung Dec 06 '16 at 03:58
-
1That's one option I have in my fork of Git. Unfortunately upstream Git didn't merge the patch. It just means you manually have to skip empty commits. – FelipeC Dec 22 '16 at 07:01
-
maybe I had found a better solution using `rev-list` to filter empty commits, see http://stackoverflow.com/questions/40988113/cherry-pick-set-of-commits-from-other-branch-skipping-empty-commits/40988114#40988114 – William Leung Dec 22 '16 at 14:29
-
1Holy cow. This wins a prize. Here's a command that only works in my private git fork. – Warren P Mar 11 '19 at 16:50
-
The first chunk is the one that matters. The second chunk is only to see what the first one would do, and it would work if you don't use `--skip-empty` (and there are no empty commits). I answered the question and I explained what Git does internally, and how you could do the same **if** the Git community had applied my patch, but they didn't. I have 400 commits applied, this particular one was not. What else do you want me to do? – FelipeC Mar 28 '19 at 02:58
The whole point of cherry-picking is that you can select a specific subset of commits you want to copy over to your branch. It exists explicitely because there are situations in which you don’t want to integrate all commits from another branch using merging.
Now, if you find yourself in a situation where you want to cherry-pick all commits that are on some other branch, then you’re exactly in the merging situation where you just want to merge that branch into your current branch to integrate all changes:
git checkout release-5
git merge master
That being said, the A..B
revision range syntax allows you to specify commits that are reachable from B
without those reachable from A
. So in your case, you would want to use release-5..master
to select all commits that are on master
but not reachable from your release-5
branch:
git cherry-pick release-5..master
But again, if you just want all those, merging is absolutely the better option because it won’t duplicate the commits and keep an actual history available.

- 369,085
- 72
- 557
- 602