Git Cherry-pick

Source: Internet
Author: User
Tags using git

Git Cherry-pick

Usage scenarios:

There are multiple branches locally, local_branch_a, Local_branch_b, ...

Commit on Local_branch_a on local branch, want to submit to local_branch_b on this,

At this time, if you are not afraid of mistakes, not too much trouble, of course, you can local_branch_b the last commit code in the rewrite to commit again.

But Git offers a better solution: Git cherry-pick <commit_id>

Specific Operating Procedures:

The first is the submission on the local_branch_a, with the submission of _id,

Then through the git log query to the submitted ID disease record,

Then switch to Local_branch_b,

Using Git Cherry-pick <commit_id>

After the command finishes checking the status,

If there is no problem and there is no conflict, it is tantamount to having executed a commit on the Loca_branch_b,

At this time, you can push directly on the local_branch_b.

code example:

Assuming now on the local_branch_a,

Git branch-vv

git status

git add <some_file>

Git commit-m "Comments"

git log

<commit_id>//Get commit_id and record

git checkout <local_branch_B>

Git branch-vv

git status

Git Cherry-pick <commit_id>

If there is no conflict, commit is already done.

If there is a conflict, you need to resolve the conflict first, you can merge manually, or you can use the Mergetool

After the conflict has been resolved, the execution

git add <merged_file>

Git commit-m "comments, use Cherry-pcik produce some conflicts, merge some file"

The execution is complete and you are ready to push.

Git Cherry-pick

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: info-contact@alibabacloud.com 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.