I have two branches develop and master. Say master is behind develop by ~20 commits. I want to merge only one of the commits (07f5722) from develop into master. How can I do that?
How to merge a specific commit in git and How do I merge a specific commit from one branch into another in Git? both say to use git cherry-pick
without much of an explanation as to how you should use it. I didn't really follow the examples from the man page either.
I tried doing the following:
git checkout -b merge-07f5722 develop
git cherry-pick 07f5722
But received this message about the cherry-pick being empty:
On branch merge-07f5722
You are currently cherry-picking commit 07f5722.
nothing to commit, working directory clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
If you wish to skip this commit, use:
git reset
Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.
The answer to git cherry-pick not working indicates that this means the cherry-pick is a no-op with no actual changes. Okay, so how do I get the changes?
NOTE: My question is nearly identical to git cherry-pick not working. However, I want to know how to accomplish what I intend to do instead of why the command I tried specifically failed.
The sequence of commands I had to use was:
git checkout -b merge-07f5722 master
git cherry-pick 07f5722 # commit from develop
git checkout master
git merge merge-07f5722
I think that your mistake was that you created your merge-07f5722
branch off of develop
. Then when you tried to do the cherry-pick your changes were already on that branch because you already had the commit. So it would result in an empty commit. Create your merge branch off of master
rather than develop
should result in a successful cherry-pick for you.