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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/user/project/merge_requests/cherry_pick_changes.md')
-rw-r--r--doc/user/project/merge_requests/cherry_pick_changes.md154
1 files changed, 106 insertions, 48 deletions
diff --git a/doc/user/project/merge_requests/cherry_pick_changes.md b/doc/user/project/merge_requests/cherry_pick_changes.md
index 14f3979cf34..2040995280e 100644
--- a/doc/user/project/merge_requests/cherry_pick_changes.md
+++ b/doc/user/project/merge_requests/cherry_pick_changes.md
@@ -7,61 +7,106 @@ type: reference, concepts
# Cherry-pick changes **(FREE)**
-GitLab implements Git's powerful feature to
-[cherry-pick any commit](https://git-scm.com/docs/git-cherry-pick "Git cherry-pick documentation")
-with a **Cherry-pick** button in merge requests and commit details.
+In Git, *cherry-picking* is taking a single commit from one branch and adding it
+as the latest commit on another branch. The rest of the commits in the source branch
+are not added to the target. You should cherry-pick a commit when you need the
+change contained in a single commit, but you can't or don't want to pull the
+entire contents of that branch into another.
-## Cherry-pick a merge request
+You can use the GitLab UI to cherry-pick single commits or entire merge requests.
+You can even cherry-pick a commit from [a fork of your project](#cherry-pick-into-a-project).
-After the merge request has been merged, a **Cherry-pick** button displays
-to cherry-pick the changes introduced by that merge request.
+NOTE:
+Support for tracking commits cherry-picked from the command line
+is tracked [in this issue](https://gitlab.com/gitlab-org/gitlab/-/issues/202215).
-![Cherry-pick merge request](img/cherry_pick_changes_mr.png)
+## Cherry-pick example
+
+In this example of cherry-picking, a Git repository has two branches: `develop` and `main`.
+This example shows a cherry-picked commit from one branch being added to another:
+
+```mermaid
+gitGraph
+ commit id: "A"
+ branch develop
+ commit id:"B"
+ checkout main
+ commit id:"C"
+ checkout develop
+ commit id:"D"
+ checkout main
+ commit id:"E"
+ cherry-pick id:"B"
+ commit id:"G"
+ checkout develop
+ commit id:"H"
+```
-After you select that button, a modal displays a
-[branch filter search box](../repository/branches/index.md#branch-filter-search-box)
-where you can choose to either:
+In this example, a cherry-pick of commit `B` from the `develop` branch is added
+after commit `E` in the `main` branch.
-- Cherry-pick the changes directly into the selected branch.
-- Create a new merge request with the cherry-picked changes.
+Commit `G` is added after the cherry-pick.
-### Track a cherry-pick
+## Cherry-pick all changes from a merge request
-> [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/2675) in GitLab 12.9.
+After a merge request is merged, you can cherry-pick all changes introduced
+by the merge request:
-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.
+1. On the top bar, select **Main menu > Projects** and find your project.
+1. On the left sidebar, select **Merge requests**, and find your merge request.
+1. Scroll to the merge request reports section, and find the **Merged by** report.
+1. In the top right, select **Cherry-pick**:
-![Cherry-pick tracking in merge request timeline](img/cherry_pick_mr_timeline_v12_9.png)
+ ![Cherry-pick merge request](img/cherry_pick_v15_4.png)
+1. In the modal window, select the project and branch to cherry-pick into.
+1. Optional. Select **Start a new merge request with these changes**.
+1. Select **Cherry-pick**.
-Each deployment's [list of associated merge requests](../../../api/deployments.md#list-of-merge-requests-associated-with-a-deployment) includes cherry-picked merge commits.
+## Cherry-pick a single commit
-NOTE:
-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).
+You can cherry-pick a single commit from multiple locations in your GitLab project.
-## Cherry-pick a commit
+### From a project's commit list
-You can cherry-pick a commit from the commit details page:
+To cherry-pick a commit from the list of all commits for a project:
-![Cherry-pick commit](img/cherry_pick_changes_commit.png)
+1. On the top bar, select **Main menu > Projects** and find your project.
+1. On the left sidebar, select **Repository > Commits**.
+1. Select the title of the commit you want to cherry-pick.
+1. In the modal window, select the project and branch to cherry-pick into.
+1. Optional. Select **Start a new merge request with these changes**.
+1. Select **Cherry-pick**.
-Similar to cherry-picking a merge request, you can cherry-pick the changes
-directly into the target branch or create a new merge request to cherry-pick the
-changes.
+### From a merge request
-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
-from the command line.
+You can cherry-pick commits from any merge request in your project, regardless of
+whether the merge request is open or closed. To cherry-pick a commit from the
+list of commits included in a merge request:
-Here's a quick example to cherry-pick a merge commit using the second parent as the
-mainline:
+1. On the top bar, select **Main menu > Projects** and find your project.
+1. On the left sidebar, select **Merge requests**, and find your merge request.
+1. In the merge request's secondary menu, select **Commits** to display the commit details page.
+1. Select the title of the commit you want to cherry-pick.
+1. In the top right corner, select **Options > Cherry-pick** to show the cherry-pick modal.
+1. In the modal window, select the project and branch to cherry-pick into.
+1. Optional. Select **Start a new merge request with these changes**.
+1. Select **Cherry-pick**.
-```shell
-git cherry-pick -m 2 7a39eb0
-```
+### From the file view of a repository
-### Cherry-pick into a project
+You can cherry-pick from the list of previous commits affecting an individual file
+when you view that file in your project's Git repository:
+
+1. On the top bar, select **Main menu > Projects** and find your project.
+1. On the left sidebar, select **Repository > Files** and go to the file
+ changed by the commit.
+1. Select **History**, then select the title of the commit you want to cherry-pick.
+1. In the top right corner, select **Options > Cherry-pick** to show the cherry-pick modal.
+1. In the modal window, select the project and branch to cherry-pick into.
+1. Optional. Select **Start a new merge request with these changes**.
+1. Select **Cherry-pick**.
+
+## Cherry-pick into a project
> - [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.
@@ -70,25 +115,38 @@ You can cherry-pick merge requests from the same project, or forks of the same
project, from the GitLab user interface:
1. In the merge request's secondary menu, select **Commits** to display the commit details page.
-1. Select the **Options** dropdown and select **Cherry-pick** to show the cherry-pick modal.
+1. In the top right corner, select **Options > 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. Select **Cherry-pick**.
+## View system notes for cherry-picked commits
+
+When you cherry-pick a merge commit in the GitLab UI or API, GitLab adds a system note
+to the related merge request thread in the format **{cherry-pick-commit}**
+`[USER]` **picked the changes into the branch** `[BRANCHNAME]` with commit** `[SHA]` `[DATE]`:
+
+![Cherry-pick tracking in merge request timeline](img/cherry_pick_mr_timeline_v15_4.png)
+
+The system note crosslinks the new commit and the existing merge request.
+Each deployment's [list of associated merge requests](../../../api/deployments.md#list-of-merge-requests-associated-with-a-deployment) includes cherry-picked merge commits.
+
## Related topics
-- The [Commits API](../../../api/commits.md) enables you to add custom messages
- to changes you cherry-pick through the API.
+- Use the [Commits API](../../../api/commits.md) to add custom messages
+ to changes when you use the API to cherry-pick.
-<!-- ## Troubleshooting
+## 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.
+### Selecting a different parent commit when cherry-picking
-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. -->
+When you cherry-pick a merge commit in the GitLab UI, the mainline is always the
+first parent. Use the command line to cherry-pick with a different mainline.
+
+Here's a quick example to cherry-pick a merge commit using the second parent as the
+mainline:
+
+```shell
+git cherry-pick -m 2 7a39eb0
+```