debian-mirror-gitlab/doc/user/project/merge_requests/cherry_pick_changes.md

98 lines
4.1 KiB
Markdown
Raw Normal View History

2019-09-04 21:01:54 +05:30
---
2020-10-24 23:57:45 +05:30
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
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
2019-09-04 21:01:54 +05:30
type: reference, concepts
---
2016-09-29 09:46:39 +05:30
2021-03-11 19:13:27 +05:30
# Cherry-pick changes **(FREE)**
2016-09-29 09:46:39 +05:30
2019-09-04 21:01:54 +05:30
GitLab implements Git's powerful feature to
[cherry-pick any commit](https://git-scm.com/docs/git-cherry-pick "Git cherry-pick documentation")
2021-04-29 21:17:54 +05:30
with a **Cherry-pick** button in merge requests and commit details.
2016-09-29 09:46:39 +05:30
2021-11-11 11:23:49 +05:30
## Cherry-pick a merge request
2016-09-29 09:46:39 +05:30
2021-03-11 19:13:27 +05:30
After the merge request has been merged, a **Cherry-pick** button displays
2018-03-17 18:26:18 +05:30
to cherry-pick the changes introduced by that merge request.
2016-09-29 09:46:39 +05:30
2021-06-08 01:23:25 +05:30
![Cherry-pick merge request](img/cherry_pick_changes_mr.png)
2016-09-29 09:46:39 +05:30
2021-03-11 19:13:27 +05:30
After you click that button, a modal displays a
[branch filter search box](../repository/branches/index.md#branch-filter-search-box)
2018-12-13 13:39:08 +05:30
where you can choose to either:
- Cherry-pick the changes directly into the selected branch.
- Create a new merge request with the cherry-picked changes.
2016-09-29 09:46:39 +05:30
2021-11-11 11:23:49 +05:30
### Track a cherry-pick
2020-04-08 14:13:33 +05:30
> [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/2675) in GitLab 12.9.
2021-03-11 19:13:27 +05:30
When you cherry-pick a merge commit, GitLab displays a system note to the related merge
request thread. It crosslinks the new commit and the existing merge request.
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
![Cherry-pick tracking in merge request timeline](img/cherry_pick_mr_timeline_v12_9.png)
2020-04-08 14:13:33 +05:30
2021-03-11 19:13:27 +05:30
Each deployment's [list of associated merge requests](../../../api/deployments.md#list-of-merge-requests-associated-with-a-deployment) includes cherry-picked merge commits.
2020-04-08 14:13:33 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2021-10-27 15:23:28 +05:30
We only track cherry-pick executed from GitLab (both UI and API). Support for tracking cherry-picked commits through the command line
is tracked [in this issue](https://gitlab.com/gitlab-org/gitlab/-/issues/202215).
2020-04-08 14:13:33 +05:30
2021-11-11 11:23:49 +05:30
## Cherry-pick a commit
2016-09-29 09:46:39 +05:30
2019-09-04 21:01:54 +05:30
You can cherry-pick a commit from the commit details page:
2016-09-29 09:46:39 +05:30
![Cherry-pick commit](img/cherry_pick_changes_commit.png)
2021-03-11 19:13:27 +05:30
Similar to cherry-picking a merge request, you can cherry-pick the changes
2018-03-17 18:26:18 +05:30
directly into the target branch or create a new merge request to cherry-pick the
changes.
2016-09-29 09:46:39 +05:30
2021-03-11 19:13:27 +05:30
When cherry-picking merge commits, the mainline is always the
first parent. If you want to use a different mainline, you need to do that
2016-09-29 09:46:39 +05:30
from the command line.
2021-03-11 19:13:27 +05:30
Here's a quick example to cherry-pick a merge commit using the second parent as the
2016-09-29 09:46:39 +05:30
mainline:
2020-03-13 15:44:24 +05:30
```shell
2016-09-29 09:46:39 +05:30
git cherry-pick -m 2 7a39eb0
```
2021-04-29 21:17:54 +05:30
### Cherry-pick into a project
2021-10-27 15:23:28 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/21268) in GitLab 13.11 behind a [feature flag](../../feature_flags.md), disabled by default.
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/324154) in GitLab 14.0.
2021-04-29 21:17:54 +05:30
WARNING:
This feature might not be available to you. Check the **version history** note above for details.
You can use the GitLab UI to cherry-pick merge requests into a project, even if the
merge request is from a fork:
1. In the merge request's secondary menu, click **Commits** to display the commit details page.
1. Click on the **Options** dropdown and select **Cherry-pick** to show the cherry-pick modal.
1. In **Pick into project** and **Pick into branch**, select the destination project and branch:
![Cherry-pick commit](img/cherry_pick_into_project_v13_11.png)
1. (Optional) Select **Start a new merge request** if you're ready to create a merge request.
1. Click **Cherry-pick**.
2021-09-04 01:27:46 +05:30
## Related links
2021-04-29 21:17:54 +05:30
2021-09-04 01:27:46 +05:30
- The [Commits API](../../../api/commits.md) enables you to add custom messages
to changes you cherry-pick through the API.
2021-04-29 21:17:54 +05:30
2019-09-04 21:01:54 +05:30
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X`.
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->