3

(It's the first time I'm trying to use git's cherry picking, so maybe I misunderstood what it is or what it can do)

While working on some new feature in a feature branch (for simplicity let's call it just next), I discovered some bugs in the current master that I fixed "on the fly" (which may not have been the best idea). Now that I think the feature branch is complete, I'd like to cherry pick some or all of the bugs fixed in next to master to make a bug-fix release before a feature release.

So I checked out master and tried (after reading the git-cherry manual page):

git cherry
git cherry next
git cherry -v next
git cherry -v next master

However none of the commands did output anything, even though there is a huge difference between next and master.

So what is the problem? Did I do something wrong, or did I misunderstand about cherry picking? The manual refers to some "origin" branch, while my branch is local.

If the cherry picking is the wrong tool, what would be the correct procedure to achieve what I'm trying to do?

U. Windl
  • 3,480
  • 26
  • 54
  • `cherry` is not `cherry-pick` though. It sounds like you want to `cherry-pick`, but you're using `cherry`...? – Amadan Sep 05 '19 at 09:49
  • The manual page for `git-cherry` says: "Find commits yet to be applied to upstream". So my guess was that I can select a commit from this list for actual cherry-pick. But that list is empty (no cherries to pick, so to say). – U. Windl Sep 05 '19 at 09:55
  • 1
    `cherry` finds commits on _current_ branch that are not applied to the _upstream_ branch. I.e. while on `master`, it finds commits on _`master`_ that are not yet in _`next`_. You want the vice versa: `git cherry master next` (or `git checkout next; git cherry master`) – Amadan Sep 05 '19 at 10:06

1 Answers1

4

git cherry and git cherry-pick are two different commands. From source git cherry: git cherry [-v] [<upstream> [<head> [<limit>]]] will show you a ID's of commits which are missing from head on upstream. In your case git cherry next master didn't show anything cause there are no commits on master, which are not present on next branch. You can check the other way git cherry master next and you will see all next commits ID's, which are not present on master.

Once you will know id's of commits, which you want to cherry pick do this with git cherry-pick commitID

Rumid
  • 1,627
  • 2
  • 21
  • 39
  • 1
    What confused me is: Manual says "`git-cherry` [*upstream* [*head*]]" with *head* defaulting to the workspace. So I guessed "git cherry next" would look for commits in `next` that are missing in the workspace (`master`). Basically I concluded from the manual that *upstream* is the more recent branch, while actually it's just reversed. – U. Windl Sep 05 '19 at 11:08