5

I can cherry pick a range of sequent commit .

for example

on branch master,I want to cherry-pick changes from d4fd8cad to HEAD of develop

git cherry-pick d4fd8cad..develop

There is an errorr

error: Commit 885c9e07264ac6b5d3960... is a merge but no -m option was given.

fatal: cherry-pick failed

how can I use the -m option ?

Venus
  • 1,184
  • 2
  • 13
  • 32
  • 2
    Possible duplicate of http://stackoverflow.com/questions/9229301/git-cherry-pick-says-38c74d-is-a-merge-but-no-m-option-was-given – gravetii Aug 04 '14 at 06:00
  • Have you looked at the [documentation](http://git-scm.com/docs/git-cherry-pick)? – Sascha Wolf Aug 04 '14 at 07:19
  • @gravetii I think cherry-pick may not do what I want.It discard all the changes made in the parent I didn't specify to -m with a merge commit – Venus Aug 04 '14 at 07:39
  • 1
    What do you want to achieve? An interactive rebase might be a better solution? You could do an interactive base in a new branch on top of develop, pick the commits you want and then do a fast forward merge to get them in to develop. I need some help with what you actually want to achieve before I can give you a proper answer. – Andreas Løve Selvik Aug 04 '14 at 09:02
  • Well, in that case cherry-pick isn't the best option. Maybe, taking a hint from the answer to the other question, you can achieve what you want by doing just a merge and a couple of other operations? – gravetii Aug 04 '14 at 12:44
  • @Lionleaf I want to apply commits d4fd8cad..HEAD in branch develop to master.and there are merge commits between d4fd8cad and HEAD – Venus Aug 04 '14 at 13:27
  • @Lionleaf ths,interactive rebase is a good idea – Venus Aug 05 '14 at 09:51

1 Answers1

3

In this case it might be better to use an interactive rebase.

To apply d4fd8cad..HEAD from branch develop to master, you can use the following command.

Make sure we are standing in develop:

git checkout develop

Branch out of develop:

git checkout -b develop-rebase

Do an interactive rebase on master. The -p option lets you keep the merge commits.

git rebase master -i -p

Delete all the lines with commits before d4fd8cad. Leaving you with the commits you wanted to cherrypick.

Save the rebase file.

Resolve conflicts, if any.

Now you have a branch that look exactly like you want your master branch to look. Take a look in gitk to verify if you want.

Now all we have to do is merge this into master. If this is not a fast-forward merge, something wrong has probably happened, so let's add the --ff-only flag

git checkout master
git merge develop-rebase --ff-only
Andreas Løve Selvik
  • 1,262
  • 16
  • 25
  • 1
    If you want to keep merge commits, do a rebase with the `-p` option – martin Aug 05 '14 at 13:59
  • 1
    -p, --preserve-merges Recreate merge commits instead of flattening the history by replaying commits a merge commit introduces. Merge conflict resolutions or manual amendments to merge commits are not preserved. This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below). – Sergei Krivonos Feb 16 '17 at 17:50