Applying Changes from a Specific Commit to Other Branches (Cherry Picking)
Suppose, you have two diverged branches,
One day, you decide to integrate changes from one specific commit in
With IntelliJ IDEA, you can cherry pick between branches right from the Version Control tool window.
To cherry pick changes between two branches
- Switch to the target branch that the changes will be integrated to.
- Open the Version Control tool window and switch to the Log tab.
From the Branch drop-down list on the toolbar, select the source branch containing the changes you want to cherry-pick.
Note that the Commits pane lists all commits performed in the selected branch. To reduce the number of items in the list, you can filter the commits by the user or date. You can also click the Highlight non-picked commits button to grey out the commits that have already been applied to the current branch.
- Select the required commit. Use the information in the Commit Details area if necessary.
- Click the Cherry-pick button on the toolbar. IntelliJ IDEA will display the Commit Changes dialog with the automatically generated commit message.
- If you want to review the changes or even modify the code before committing it to the target branch, you can do so in the difference viewer available from this dialog.
- When done, click Commit to cherry-pick the selected changes.
Note that if you click Cancel in the Commit Changes dialog, a separate changelist will be created with the selected changes that you can see in the Local Changes tab. You can review these changes and commit them later if necessary.