Git cherry-pick Merge a commit

Source: Internet
Author: User
Tags using git

1, the use of methods and their role

  git cherry-pick can choose one or a few commits (s) in one branch to do the operation (the object is commit). For example, suppose we have a stable version of the branch, called V2.0, there is a development version of the Branch v3.0, we can not directly merge two branches, which will lead to stable version confusion, but also want to add a v3.0 in the function to v2.0, here can use Cherry-pick.

is to resubmit a commit that already exists;

Here's how to use it:

ID>

Queries that query the commit ID can use git log queries (query version history), and the simplest syntax is as follows:

git log

The detailed git log syntax is as follows:

git log [<options>] [<since>.. <until>] [[--] <path> ...]

The main parameter options are as follows:

-P: Show the difference between each update by patch

--stat: Displays statistics of modified files for each update

--shortstat: Show only the last number of rows in--stat add modify Delete statistics

--name-only: Displays the list of files after the modified submission information

--name-status: Displays a list of new, modified, and deleted files

--abbrev-commit: Displays only the first few characters of the SHA-1, not all 40 characters

--relative-date: Using a shorter relative time display (for example: "Weeks ago")

--graph: Displays the branch merge history of the ASCII graphic representation

--pretty: Displaying historical submissions in other formats

The result is probably as follows:

0771a0c107dbf4c96806d22bbc6ef4c58dfe7075<[email protected]>Date:   814 :0800+     [Modify] [what] commit comment information

Where 0771a0c107dbf4c96806d22bbc6ef4c58dfe7075 is our commit ID.

Note: When Cherry-pick is finished, a new commit will be generated; The new commit hash value is different from the original, but the identity name is the same; (The commit ID will change)

2. Practice

First switch to the branch where you want to add a commit, such as: you want to add the commit above the a branch to the B branch, we can first switch to the B branch above. (Note: Cherry-pick is a local operation, if someone has a new commit on the a branch after you pull the code, you need the pull code to do the Cherry-pick, for the reason and the error, see the last).

git checkout B

Merge 0771a0c107dbf4c96806d22bbc6ef4c58dfe7075 this commit (commit) to the B branch. Under normal circumstances, you can give all the commit ID, or you can just give the previous paragraph, as long as you do not have this section of the submission of repetition, the rest of the git will help you fill.

 0771a0c107dbf4c  #将上面的commit ID is  0771a0c107dbf4c96806d22bbc6ef4c58dfe7075 commits are added to branch B above

1. The Success situation

Well, the following situation proves that you have succeeded.

Finished one cherry-'origin/b'1 commits.

2. Situations of conflict

Here is a file conflict, and 15a2b6c61927e5aed6718de89ad9dafba939a90b this commit conflict

Automatic cherry-pick failed.   ' git add <paths> ' ' git rm <paths> ' and commit the result with:          -C 15a2b6c61927e5aed6718de89ad9dafba939a90b

The method of conflict resolution is also the same as normal, Manual check.

1) View conflicting files

Using git status

Both modified:      APP/MODELS/USER.RB

2) Open the file above to resolve the conflict. Execute the Add command, execute the commit command, and finally commit.

3, some of the errors encountered

Use the following Cherry-pick command to execute a commit (number: 77C6905DCF7F946CFF594A69A33D12E22BEDFAE4)

Git Cherry-pick 77c6905dcf7f946cff594a69a33d12e22bedfae4

The following error has occurred:

Fatal:bad Object 77c6905dcf7f946cff594a69a33d12e22bedfae4

scenario and the cause of the error:

My situation is a commit of the synchronization a branch in the B branch, which appears as a header error. I saw this commit on the web directly on the a branch, and then I did git cherry-pick xxx directly in the local B branch. There was this problem. After trying the problem is out of the I did not cut to the B branch pull a bit. The summary is that git Cherry-pick is a local feature, and this commit is needed locally to be git cherry-picK.

Thanks: Thank you for reading! There are errors please correct, there are other missing things please advise, thank you!

Git cherry-pick Merge a commit

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.