cherry-pick git command of

git cherry-pick a merge commit

git cherry-pick can select one or more branches of a commit (s) to perform the operation (the operation target is the commit ).


1, using the method & demand

Scenes:

Suppose we have a stable release branch, called v2.0, plus a branch v3.0 development version, we can not directly merge the two branches, which can cause confusion stable version, but want to add a v3.0 the function into v2.0, here you can use cherry-pick up.

Instructions:

git cherry-pick <commit id>

Query commit id query can use git log queries (queries version of history), the simplest syntax is as follows:

git log

Detailed git log syntax is as follows:

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

      The main parameter options are as follows:

             -p: Show differences between each update as patches

            --stat: display statistics for each update modified files

            --shortstat: only the last number of rows --stat add modify delete statistics

            --name-only: make the list of documents is displayed after submitting the information has been modified

            --name-status: display a list of files to add, modify and delete

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

            --relative-date: time display using relatively short (eg: "two weeks ago")

            --graph: Merge branch history displays a graphical representation of the ASCII

            --pretty: Use other formats Show commits

The results probably as follows:

commit 3b64693a060a8cf07c66a9545ef969d52f9cbe8c
Author: domi.song <[email protected]>
Date: Tue Jun 25 22:07:49 2019 +0800

Fixed # TSB-11111 Submissions

Which 3b64693a060a8cf07c66a9545ef969d52f9cbe8c is our commit id;

Note: When finished execution cherry-pick, will generate a new submission; this new hash value of the original submission and different, but the same identification name; (commit id becomes)

 


 2, reference examples

First you have to add a switch to branch commit, such as: A branch you want to commit the above is added to the branch B above, we can switch to the first branch B above. (Note: cherry-pick is a local operation, if the code after you pull someone has a new commit on the branch A, you need to pull the code during cherry-pick, error causes and see the final).

git checkout B

The 3b64693a060a8cf07c66a9545ef969d52f9cbe8c this commit (submitted) into branch B above. Under normal circumstances, can be given all of the commit id, it can be given only in front of the paragraph, as long as you did not submit this period repeated like, the rest git will help you fill.

Cherry-Pick Git 3b64693a060a8cf07c6   # commit id of the above 3b64693a060a8cf07c66a9545ef969d52f9cbe8c filed added to the upper branch B

result:

1. Successful case

  Hopefully, the following are true to prove that you have succeeded

DomideMacBook-Pro: songpengju$ git cherry-pick 583f3b1201999aaaf0728ad73dcb132c00744531
[biguiyuan-v6.5-report-browser-mobile-new 8fd59f0c5c]   Fixed #TSB-11111 XXXXXXXX
 Author: bert <[email protected]>
 Date: Wed Jun 26 19:08:49 2019 +0800
 1 file changed, 10 insertions(+)

2. conflict situations

  Here there is a file conflict, and XXXXXXXXXXXXXXXXXXXX submit this conflict, as shown below:

 The method of conflict resolution is also the same as ordinary, manual inspection.

1) Check conflicting files

  Use git status

2) Open the file above resolve the conflict. Execute add command, run the commit command, and finally submitted to the

  Here recommend a git visualization tool --GitKraKen, relatively easy to use, pro-test


 

3, some errors

Use the following command cherry-pick a commit (number: 77c6905dcf7f946cff594a69a33d12e22bedfae4)

git cherry-pick 77c6905dcf7f946cff594a69a33d12e22bedfae4

The following error occurred:

fatal: bad object 77c6905dcf7f946cff594a69a33d12e22bedfae4

Scene and the cause of the error:

      My situation is a commit in synchronization A branch of the B branch, an error has occurred, such as the title. I saw this commit A new branch submitted directly on the web, then I git cherry-pick xxx carried out directly in the local B branch. The emergence of this problem. After attempts the problem is not in me cut to the B branch pull it. Summary translation is git cherry-pick local characteristics, to have this local commit can be git cherry-pick .

 

Acknowledgments : Thanks for reading! Please errors to be corrected, there is a lack of other stuff please let us know, thank you!

PS: Reference connection: https://www.cnblogs.com/0201zcr/p/5752771.html

 

Guess you like

Origin www.cnblogs.com/domisong/p/12581399.html