Git cherry-pick. How to put committed commit from one branch to another

Source: Internet
Author: User

Actual problems:
A commit (38361a68138140827b31b72f8bbfd88b3705d77a) is created on the local master branch. How can I place it on the local old_cc branch?

One way: Use cherry-pick. According to the GIT documentation:

Apply the changes introduced by some existing commits

Is to apply an existing commit (can be understood as submitting again)

Simple usage:

Git cherry-pick <commit ID>
 


For example:
$ Git checkout old_cc
$ Git cherry-pick 38361a68 # The 38361a68 number is located:

 
$ Git log
Commit 38361a68138140827b31b72f8bbfd88b3705d77a
Author: Siwei Shen <[email protected]>
Date: Sat Dec 10 00:09:44 2011 + 0800


1. if it succeeds, it will be submitted normally. Result:

Finished one cherry-pick.
# On branch old_cc
# Your branch is ahead of 'origin/old_cc 'by 3 commits.


2. If there is a conflict in the cherry-pick Process

Automatic cherry-pick failed. After resolving the conflicts,
Mark the corrected paths with 'git add <paths> 'or 'git Rm <paths>'
And commit the result:

Git commit-C 15a2b6c61927e5aed6718de89ad9dafba939a90b


As with normal conflicts, manually solve them:
2.1 $ git status # Check which files conflict

Both modified: APP/models/user. Rb


2.2 $ Vim APP/models/user. RB # solve it manually.
2.3 $ git add APP/models/user. Rb
2.4 git commit-C <New commit number>

 

========================================================== ==============

 

Git's wrong operations lead to the loss of important commit, which is really hard to get;
Finally, I found the lost commit through the GIT artifact, but there are some points to summarize and reflect on. At the same time, I need to learn more about git. I would like to present this article for your reference.

Execute git reset -- hard head ~ 1. commit3 is deleted, but the reset is incorrect ......
Fortunately, there is regret medicine (I lamented the strength of git, which was taken into account by the accident). To restore commit3 with full blood, perform the following steps:

Java code
  1. Git reflog
  2. 502dd0f [email protected] {0}: Head ~ 1: updating head
  3. 147b3b5 [email protected] {1}: commit: test3
  4. 502dd0f [email protected] {2}: commit: Test2
  5. 0692c03 [email protected] {3}: Commit (initial): test1
  6. Git reset -- hard 502dd0f
  7. Git cherry-pick 147b3b5



The lost commit3 has finally arrived ~~~~
Although there are powerful tools, we need to sum up and reflect on the fact that using reset hard with caution is not a good choice for Reset merge.

 

Original article: http://sg552.iteye.com/blog/1300713

Reference: http://dmouse.iteye.com/blog/1797267

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.