This article is edited and sorted from:
http://sg552.iteye.com/blog/1300713 http://web.mit.edu/bitbucket/git-doc/git-cherry-pick.txt git Cherry-pick Used to apply a commit modification of another local branch to the current branch.
Practical ProblemsA commit (38361A68138140827B31B72F8BBFD88B3705D77A) was made on the local master branch, and how to place it on the local OLD_CC branch. One approach: using Cherry-pick. According to GIT documentation: apply the changes introduced by some existing commits is to apply to an existing commit (understandable to resubmit)
Simple Usage: Git cherry-pick <commit id> For example: $ git checkout old_cc $ git cherry-pick 38361a68 1. If it goes well, it will be submitted normally. Result: finished one cherry-pick. # on Branch OLD_CC # Your branch are 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 with:
Git commit-c 15a2b6c61927e5aed6718de89ad9dafba939a90b
As with ordinary conflicts, manually resolve: Execute git status to see which files conflict $ git status both modified:app/models/user.rb then manually resolve the conflicting files and then use git add to change to Index, and finally executes the git commit modification. $ vim app/models/user.rb $ git add app/models/user.rb git commit-c < original commit > Git-cherry-pick (1) ============= =====
NAME----Git-cherry-pick-apply The changes introduced by some existing commits
Synopsis--------' git Cherry-pick ' [--edit] [-n] [-M parent-number] [-S] [-X] [--ff] <commit>
DESCRIPTION-----------
Given one or more existing commits, apply the change to each one introduces, recording a new commit to each. This requires your working is clean (no modifications from the head commit).
When it isn't obvious how to apply a change, the following happens:
1. The current branch and ' head ' pointer stay in the last commit successfully made. 2. The ' Cherry_pick_head ' ref is set to point at the commit this introduced the change this is difficult to apply. 3. Paths in which the "applied cleanly are updated both in the" index file and in your working. 4. For conflicting paths, the index file records up to three versions, as described in the ' TRUE MERGE ' section of L INKGIT:GIT-MERGE[1]. The working tree files would include a description of the conflict bracketed by the usual conflict markers ' <<& lt;<<<< ' and ' >>>>>>> '. 5. No other modifications are made.
LINKGIT:GIT-MERGE[1] For some hints on resolving such conflicts.
OPTIONS-------<commit>.:: Commits to Cherry-pick. For a more complete list of ways to spell commits, in the linkgit:gitrevisions[7]. Sets of commits can be passed but no traversal are done by default, as if the '--no-walk ' option was specified, : Git-rev-list[1].
-E::--edit:: With this option, ' Git cherry-pick ' 'll let you edit the ' commit ' and prior to committing.
-X:: When recording the Commit, append to the original commit message a note that indicates which commit this change is C Herry-picked from. Append the note is for cherry picks without conflicts. Do don't use this option if you are are cherry-picking from your private branch because the information are useless to the Recipi Ent. If on the other hand you are cherry-picking between two publicly visible (branches. E.g a fix to a backporting Branch for the older release from a development branch), adding this information can be useful.
-R:: It used to is the command defaulted to do ' X ' described above, and '-R ' is to disable it. Now the "is" not "do ' X ' So" is a no-op.
-M Parent-number::--mainline parent-number:: Usually you cannot cherry-pick a merge because your do not know which of The merge should be considered the mainline. This option specifies the "parent number" (starting from 1) of the mainline and allows Cherry-pick to replay the change RelA Tive to the specified parent.
-N::--no-commit:: Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commits to your working and the index, without Makin G any commit. In addition, where this option is used, your index does not have to match's head commit. The Cherry-pick is do against the beginning state of your index. + This is useful the cherry-picking more than one commits ' effect to your index in a row.
-S::--signoff:: Add signed-off-by line at the "end of" the commit message.
--FF:: If the same as the Cherry-pick ' Ed commit, then a fast forward to this commit Be performed.
--STRATEGY=<STRATEGY>:: Use the given merge strategy. Should be used once. The MERGE Strategies section in Linkgit:git-merge[1] for details.
-x<option>::--strategy-option=<option>:: Pass the merge strategy-specific option through to the merge Strate Gy. LINKGIT:GIT-MERGE[1] for details.
Examples--------git cherry-pick master::
Apply the change introduced by the commit in the tip of the The Master branch and create a new commit with the.
Git Cherry-pick. Master:: Git cherry-pick ^head master::
Apply the changes introduced by all commits this are ancestors of master but not of a to produce new commits.
Git cherry-pick master{tilde}4 master{tilde}2::
Apply the changes introduced by the fifth and third last commits pointed to through master and create 2 new commits with these Changes.
Git cherry-pick-n master~1 Next::
Apply to the working tree and the index of the changes introduced by the second of the last commit pointed to by master and by the L AST commit pointed to by next, the But do not create any commits with these changes.
Git Cherry-pick--ff. Next::
If history is linear and a ancestor of next, update the working tree and advance to match next. Otherwise, apply the changes introduced by those commits this are in next but not head to the current branch, creating a N EW commit for each new change.
git rev-list--reverse master \--README | Git cherry-pick-n--stdin::
Apply the changes introduced by all commits on the master branch which touched README to the working tree and Index Can be inspected and made to a single new commit if suitable.
The following sequence attempts to backport a patch, bails out because the code of the patch applies to has changed much, And then tries again, this time exercising more care about matching up the context lines.
------------$ git cherry-pick topic^ <1> $ git diff <2> $ git reset--merge orig_head &NBS P <3> $ git cherry-pick-xpatience topic^ <4>------------<1> Apply the change that Wo Uld be shown by ' Git show topic^ '. In this example, the patch does isn't apply cleanly, so information about the conflict are written to the index and working t Ree and no new commit results. <2> summarize changes to be reconciled <3> cancel the Cherry-pick. in other words, return to the Pre-cherry-pick state, preserving any local modifications you had in the working. <4> try to apply the change introduced by ' topic^ ' again, spending extra time to avoid mistakes based on INCORRECTL Y matching context lines.
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.