Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cherry_picking.md « git « topics « doc - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 98458133937c8301696397c1642ecda85fcf3421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
stage: Create
group: Source Code
info: 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
comments: 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:

- Backport bug fixes from the default branch to previous release branches.
- Copy changes from a fork
  [to the upstream repository](../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-into-a-project).

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

- Cherry-pick [all changes from a merge request](../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-a-merge-request).
- Cherry-pick [a single commit](../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-a-commit).
- Cherry-pick [from a fork to the upstream repository](../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-into-a-project).

## 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:

   ```shell
   git checkout main
   git checkout -b stable
   ```

1. Change back to the default branch:

   ```shell
   git checkout main
   ```

1. Make your changes, then commit them:

   ```shell
   git add changed_file.rb
   git commit -m 'Fix bugs in changed_file.rb'
   ```

1. Display the commit log:

   ```shell
   $ git log

   commit 0000011111222223333344444555556666677777
   Merge: 88888999999 aaaaabbbbbb
   Author: user@example.com
   Date:   Tue Aug 31 21:19:41 2021 +0000
   ```

1. 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.

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

   ```shell
   git checkout stable
   ```

1. Cherry-pick the commit into the `stable` branch, and change `SHA` to your commit
   SHA:

   ```shell
   git cherry-pick <SHA>
   ```

## Related topics

- Cherry-pick commits with [the Commits API](../../api/commits.md#cherry-pick-a-commit)
- Git documentation [for cherry-picks](https://git-scm.com/docs/git-cherry-pick)