git Cherry-pick use guide _git

Source: Internet
Author: User

Git cherry-pick can select one or several commit (s) from one branch to operate. For example, suppose we have a stable version of the branch, called V2.0, and there is a development version of the Branch v3.0, we can not directly merge two branches, which will lead to a stable version of the chaos, but also want to add a v3.0 function to v2.0, where you can use Cherry-pick, In fact, it is to resubmit the existing commit.

Simple usage:
git cherry-pick <commit id>
Note: When the Cherry-pick is finished, a new commit is generated, and the new commit hash value is different from the original, but the identity name is the same;

For example:
$ git Checkout v2.0 branch
$ git cherry-pick 38361a55 # This 38361a55 number, located in the v3.0 branch:

$ git log
Commit 38361a55138140827b31b72f8bbfd88b3705d77a
Date:sat Dec 10 00:11:44 2016 +0800

1. If it goes well, it will be submitted normally. Results:

Finished one cherry-pick.
On Branch v2.0 Branch
Your Branch is ahead of ' ORIGIN/OLD_CC ' by 3 commits.

2. If there is a conflict during the Cherry-pick process

Automatic Cherry-pick failed.
After resolving the "Conflicts,mark" corrected paths with ' git add <paths> ' or ' git rm <paths> ' and commit th E result with:
Git commit-c 15a2b6c61927e5aed6111de89ad9dafba939a90b
Error:could not apply 0549563 ... Dev
Hint:after resolving the conflicts, mark the corrected paths
Hint:with ' git add <paths> ' or ' git rm <paths> '
Hint:and commit the result with ' git commit '

As with ordinary conflicts, manual resolution:

2.1 $ git status # see which files conflict

Both Modified:app/models/

2.2 $ vim App/models/ # manually resolve it.

2.3 $ git Add App/models/

2.4 Git commit-c < new commit number >

2.5 Again Cherry-pick remaining commit

If prompted:

Error:a Cherry-pick or revert is already in progress
Hint:try "Git Cherry-pick" (--continue | --quit | --abort) "
Fatal:cherry-pick failed

The corresponding action is performed:

Git Cherry-pick--continue
Git Cherry-pick--quit
Git Cherry-pick--abort

Command collection: Git cherry-pick <commit id>: Merging a single submit git cherry-pick-x <commit id>: Ibid., different: Keep the original submitter information.
Git starts with the 1.7.2 version to support batch Cherry-pick, which is a commit that can cherry-pick one interval at a time. git Cherry-pick <start-commit-id> <end-commit-id> git Cherry-pick <start-commit-id>^. <end-commit-id>

The former represents the submission Cherry-pick to the current branch between <start-commit-id> to <end-commit-id> (left open and right closed, not including Start-commit-id);
The latter has the representation of the "^" sign to Cherry-pick to the current branch between <start-commit-id> to <end-commit-id> (closed intervals, including Start-commit-id).
where,<start-commit-id> to <end-commit-id> only need the first 6 bits of Commit-id, and <start-commit-id> in time must be earlier than < End-commit-id>
Note: The above merge requires manual push code.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.