diff options
Diffstat (limited to 'doc/topics/git')
-rw-r--r-- | doc/topics/git/cherry_picking.md | 55 | ||||
-rw-r--r-- | doc/topics/git/git_rebase.md | 9 | ||||
-rw-r--r-- | doc/topics/git/index.md | 6 | ||||
-rw-r--r-- | doc/topics/git/lfs/migrate_to_git_lfs.md | 5 | ||||
-rw-r--r-- | doc/topics/git/numerous_undo_possibilities_in_git/index.md | 3 |
5 files changed, 57 insertions, 21 deletions
diff --git a/doc/topics/git/cherry_picking.md b/doc/topics/git/cherry_picking.md index 4a875e25e1b..64d1914019d 100644 --- a/doc/topics/git/cherry_picking.md +++ b/doc/topics/git/cherry_picking.md @@ -5,49 +5,76 @@ info: To determine the technical writer assigned to the Stage/Group associated w comments: false --- -# Cherry pick **(FREE)** +# Cherry-pick a Git commit **(FREE)** -Given an existing commit on one branch, apply the change to another branch. +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: -This can be useful for backporting bug fixes to previous release branches. Make -the commit on the default branch, and then cherry pick it into the release branch. +- 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). -## Sample workflow +You can cherry-pick commits from the command line. In the GitLab user interface, +you can also: -1. Check out a new `stable` branch from the default branch: +- 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 master + git checkout main git checkout -b stable ``` 1. Change back to the default branch: ```shell - git checkout master + git checkout main ``` -1. Make any required changes, then commit the changes: +1. Make your changes, then commit them: ```shell git add changed_file.rb git commit -m 'Fix bugs in changed_file.rb' ``` -1. Review the commit log and copy the SHA of the latest commit: +1. Display the commit log: ```shell - git log + $ git log + + commit 0000011111222223333344444555556666677777 + Merge: 88888999999 aaaaabbbbbb + Author: user@example.com + Date: Tue Aug 31 21:19:41 2021 +0000 ``` -1. Check out the `stable` branch: +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 by using the SHA copied previously: +1. Cherry-pick the commit into the `stable` branch, and change `SHA` to your commit + SHA: ```shell - git cherry-pick <commit SHA> + git cherry-pick <SHA> ``` + +## Related links + +- 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) diff --git a/doc/topics/git/git_rebase.md b/doc/topics/git/git_rebase.md index 0e288f1445e..b09f9fa0f6c 100644 --- a/doc/topics/git/git_rebase.md +++ b/doc/topics/git/git_rebase.md @@ -228,8 +228,13 @@ git push --force-with-lease origin my-feature-branch ``` If the branch you want to force-push is [protected](../../user/project/protected_branches.md), -you can't force-push to it unless you unprotect it first. Then you can -force-push and re-protect it. +you can't force push to it unless you either: + +- Unprotect it. +- [Allow force push](../../user/project/protected_branches.md#allow-force-push-on-a-protected-branch) + to it. + +Then you can force push and protect it again. ## Merge conflicts diff --git a/doc/topics/git/index.md b/doc/topics/git/index.md index c1e766a7c48..e95d8121b66 100644 --- a/doc/topics/git/index.md +++ b/doc/topics/git/index.md @@ -34,8 +34,8 @@ The following resources can help you get started with Git: - [Edit files through the command line](../../gitlab-basics/command-line-commands.md) - [GitLab Git Cheat Sheet (download)](https://about.gitlab.com/images/press/git-cheat-sheet.pdf) - Commits: - - [Revert a commit](../../user/project/merge_requests/revert_changes.md#reverting-a-commit) - - [Cherry-picking a commit](../../user/project/merge_requests/cherry_pick_changes.md#cherry-picking-a-commit) + - [Revert a commit](../../user/project/merge_requests/revert_changes.md#revert-a-commit) + - [Cherry-picking a commit](../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-a-commit) - [Squashing commits](../gitlab_flow.md#squashing-commits-with-rebase) - [Squash-and-merge](../../user/project/merge_requests/squash_and_merge.md) - [Signing commits](../../user/project/repository/gpg_signed_commits/index.md) @@ -58,7 +58,7 @@ The following are resources on version control concepts: You can do many Git tasks from the command line: - [Bisect](bisect.md). -- [Cherry pick](cherry_picking.md). +- [Cherry-pick](cherry_picking.md). - [Feature branching](feature_branching.md). - [Getting started with Git](getting_started.md). - [Git add](git_add.md). diff --git a/doc/topics/git/lfs/migrate_to_git_lfs.md b/doc/topics/git/lfs/migrate_to_git_lfs.md index d1231257f38..2786368a9d7 100644 --- a/doc/topics/git/lfs/migrate_to_git_lfs.md +++ b/doc/topics/git/lfs/migrate_to_git_lfs.md @@ -7,6 +7,11 @@ description: "How to migrate an existing Git repository to Git LFS with BFG." # Migrate a Git repository into Git LFS with BFG +WARNING: +The following documentation is deprecated. We recommend using +[`git lfs migrate`](https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-migrate.1.ronn) +instead of the method documented below. + Using Git LFS can help you to reduce the size of your Git repository and improve its performance. diff --git a/doc/topics/git/numerous_undo_possibilities_in_git/index.md b/doc/topics/git/numerous_undo_possibilities_in_git/index.md index 4d58c7ab455..9786d1399f7 100644 --- a/doc/topics/git/numerous_undo_possibilities_in_git/index.md +++ b/doc/topics/git/numerous_undo_possibilities_in_git/index.md @@ -209,7 +209,7 @@ To recover from multiple incorrect commits: The commits are now `A-B-C-D-E`. Alternatively, with GitLab, -you can [cherry-pick](../../../user/project/merge_requests/cherry_pick_changes.md#cherry-picking-a-commit) +you can [cherry-pick](../../../user/project/merge_requests/cherry_pick_changes.md#cherry-pick-a-commit) that commit into a new merge request. NOTE: @@ -388,7 +388,6 @@ git filter-branch --tree-filter 'rm filename' HEAD The `git filter-branch` command might be slow on large repositories. Tools are available to execute Git commands more quickly. -An alternative is the open source community-maintained tool [BFG](https://rtyley.github.io/bfg-repo-cleaner/). These tools are faster because they do not provide the same feature set as `git filter-branch` does, but focus on specific use cases. |