/ d365

[D365] Git Cherry-Picking

For those of you, who are not familiar with cherry-picking with git, I'll explain it in a few words.

What is cherry-picking?

There is a little bit of documentation and a lot of discussions on stack-exchange about cherry-picking.
Short version:

You can pick selected commits from another branch and apply only those commits to your current branch.

Long version:
You select one or more commits from another branch than your current working branch and apply only those commits to your current branch with the cherry-pick command.

$ git cherry-pick cfc3c3e1
Finished one cherry-pick.
[master cfc3c3e1] bugfix

Why use cherry-picking?

It is often used to take single commits of a local branch, merge them to the master / feature branch and delete the rest of the local branch. Another case is when one developer needs some changes from another to continue working but not all of the changes from the first one are ready yet. So just cherry-pick the commits containing the wanted objects from his branch.

How does that work with Visual Studio?

First of all imagine you have two branches:

  • master which is your main branch.
  • NewLabels which is a feature branch currently under development.

cherrypickvs_branches

Quick steps (long version below):

  • Check out target branch (e.g. master)
  • Right click source branch > View History (e.g. on branch NewLabels)
  • Right click wanted commit > Cherry-Pick (e.g. on commits cfc3c3e1 and 50fed86e)
  • Commit and synchronize

With details:

  1. Check out target branch (e.g. master)
    cherrypickvs_checkout
  2. Right click source branch > View History (e.g. on branch NewLabels)
    Note we are now on the master branch (yellow circle)
    cherrypickvs_viewhistory
  3. Right click wanted commit > Cherry-Pick (e.g. on commits cfc3c3e1 and 50fed86e)
    cherrypickvs_pickcommit
  4. Commit and synchronize
    Finally commit and sync changes to push them to VSTS.
[D365] Git Cherry-Picking
Share this

Subscribe to robsCode