แชร์ผ่าน


Copy changes with cherry-pick

TFS 2018

Visual Studio 2019 | Visual Studio 2022

Git cherry-pick copies the changes from one or more source branch commits to a target branch. Unlike merge or rebase, cherry-pick lets you select specific source branch commits. For each source branch commit that you cherry-pick, Git creates a corresponding commit on the target branch.

You can cherry-pick to tackle these common tasks:

  • Deploy a specific feature from one branch to another.
  • Copy work that you committed on the wrong branch.
  • Apply a bug fix on multiple branches.

For an overview of the Git workflow, see Azure Repos Git tutorial.

Cherry-pick a commit

Azure Repos

Azure Repos provides limited support for cherry-picking, and only for the purpose of creating a pull request to apply a hotfix on a target branch. For more information, see Improving Azure DevOps cherry-picking.

The Cherry-pick option in the pull request menu in Azure Repos does the following:

  1. Creates a new topic branch from the pull request's target branch.
  2. Cherry-picks all changes from the pull request's source branch to the new topic branch.
  3. Prompts you to create a new pull request to merge the new topic branch into another target branch.

For a step-by-step tutorial, see Create a new pull request with cherry-pick.

GitHub

The GitHub web interface doesn't support cherry-picking, but GitHub Desktop does. For step-by-step guidance on how to cherry-pick in GitHub Desktop, see Cherry-picking a commit.

Next steps