debian-mirror-gitlab/doc/topics/git/cherry_picking.md
2021-11-11 11:23:49 +05:30

2.5 KiB

stage group info comments
Create Source Code To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments false

Cherry-pick a Git commit (FREE)

In Git, you can cherry-pick a commit (a set of changes) from an existing branch, and apply those changes to another branch. Cherry-picks can help you:

You can cherry-pick commits from the command line. In the GitLab user interface, you can also:

Cherry-pick from the command line

These instructions explain how to cherry-pick a commit from the default branch (main) into a different branch (stable):

  1. Check out the default branch, then check out a new stable branch based on it:

    git checkout main
    git checkout -b stable
    
  2. Change back to the default branch:

    git checkout main
    
  3. Make your changes, then commit them:

    git add changed_file.rb
    git commit -m 'Fix bugs in changed_file.rb'
    
  4. Display the commit log:

    $ git log
    
    commit 0000011111222223333344444555556666677777
    Merge: 88888999999 aaaaabbbbbb
    Author: user@example.com
    Date:   Tue Aug 31 21:19:41 2021 +0000
    
  5. Identify the commit line, and copy the string of letters and numbers on that line. This information is the SHA (Secure Hash Algorithm) of the commit. The SHA is a unique identifier for this commit, and you need it in a future step.

  6. Now that you know the SHA, check out the stable branch again:

    git checkout stable
    
  7. Cherry-pick the commit into the stable branch, and change SHA to your commit SHA:

    git cherry-pick <SHA>