You’re working on target-branch. You create a new branch from it:
|
|
You make a first commit specific to source-branch, then a second commit with changes that should also live on target-branch.
You need to bring only that last commit back to target-branch. How do you perform this task?
The Solution
|
|
When you pass a branch name without a range, git cherry-pick picks only the latest commit of that branch.
Cherry-Picking Multiple Commits
If you need the last two commits instead:
|
|
The range source-branch~2..source-branch means “all commits after the second-to-last up to and including the tip.”
Handling Empty Cherry-Picks
You may encounter this message:
|
|
It means the changes from that commit already exist on target-branch. The commit produces no diff.
You have two options:
|
|
This typically happens when a previous merge or cherry-pick already brought the changes in, or when conflict resolution accepted the target branch’s version entirely.
Follow me
Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.
Credit: Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.