Cherry-pick a Commit

Cherry picking is the act of picking a commit from one branch and applying it to another. It is mainly used when you don’t want to merge the whole branch and you just want some of the commits that were made to the branch. This operation can be useful for undoing changes, like when a commit has been accidentally made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.

To cherry-pick a commit in a merged MR:

  1. From the Repositories drop-down list, select the Git repository.
  2. Click the History Graph Graph icon toggle button and then enter the branch name(s) in the text box to the right of the toggle button or select them from the drop-down list.
  3. On the right side of the page, click the Logs tab.
  4. In the history graph, find the commit you want to pick and click its link.


    Description of history-graph-commit-cherry-pick-selected.png follows
    Description of the illustration history-graph-commit-cherry-pick-selected.png

    The Compare view is displayed, showing the branch that the change was merged into, the branch that contains the change being merged, and the change itself, at the file level.


    Description of compare-view-successful-merge.png follows
    Description of the illustration compare-view-successful-merge.png

  5. Click the Actions Actions menu menu and select Cherry Pick....

    The Cherry-pick commit dialog box is displayed.


    Description of blank-cherry-pick-commit-dialog.png follows
    Description of the illustration blank-cherry-pick-commit-dialog.png

  6. In the Pick onto field, use the selector to choose a starting point (the target branch) in which the commit will be created.
  7. Use this field to check whether the change you want to make is possible or not:

Use the Git Command Line as an Alternative to the VB Studio Git User Interface

You can use the Git command line instead of using VB Studio's Git user interface to cherry-pick a commit in one branch and add it to another.

The git cherry-pick command is relatively straightforward:
git cherry-pick <commit-ID>
where <commit-ID> is a commit reference.

You need to use the git log command to find a command reference. There are several options you can use with git log to format and filter the results. For example, you could use the --graph option to draws an ASCII graph that represents the commit history's branch structure. This option is often used with the --oneline and --decorate commands so you can see which commit belongs to which branch. The --decorate flag makes the git log command display all of the references, such as branches, tags, and so on, that point to each commit.

You can also use the Git command line to create a merge request, when one is needed. See Create a Merge Request from the Command Line.