-1

I have 3 branches, m being head of master, while g and h are single commit branches. I cannot do a rebase or merge at this point. What I want is to cherry pick the changes in g and h on top of master without commiting them, just having them unstaged. There are no conflicts between these 3. However, I can only cherry pick either g or h. When I try to cherry pick the other, the cherry pick fails:

error: your local changes would be overwritten by cherry-pick.
hint: commit your changes or stash them to proceed.
fatal: cherry-pick failed

Is it possible to do this?

Ionut Duduc
  • 1
  • 1
  • 1
  • You could stash them instead of committing. – troy Apr 10 '20 at 12:17
  • “What I want is to cherry pick the changes in g and h on top of master without commiting them, just having them unstaged” Self contradiction. A cherry pick is a commit. And you must commit before starting. You could commit, then cherry pick g, then cherry pick h, working out any merge conflicts, and then reset the index. But it is unclear why you would want to do that. Commits are good, not bad. – matt Apr 10 '20 at 12:26

2 Answers2

0

You should commit your changes on branch where you trying to cherry-pick something. No active changes should be present, and then you will be able to cherry-pick any number of commits from any branches

0

First, look your git status, some files has changed in the working directory or index isn't clear. Than you could hide changes in stash using git stash or reset them or commit them.

If you want to merge commits from g and h branches into m than do this

1)

git checkout m
git cherry-pick <commit_from_g>
git cherry-pick <commit_from_h>
git rebase -i #squash last to commits into one

or

2)

git rebase m h
git rebase h g
git checkout g
git rebase -i #squash last to commits into one
sergzemsk
  • 164
  • 3
  • 12