Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cherry pick a range of sequently commits including merge

Tags:

git

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 ?

like image 251
Venus Avatar asked Oct 20 '22 04:10

Venus


1 Answers

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
like image 64
Andreas Løve Selvik Avatar answered Oct 22 '22 23:10

Andreas Løve Selvik