The difference between git cherry-pick and git merge
For multi-branch codebases, it is a common requirement to move code from one branch to another.
There are two situations at this time. In one case, you need all the code changes from another branch, then use git merge. In another case, you only need some code changes (certain commits), then you can use git cherry-pick.
The operation object of git merge is branch, and the operation object of git cherry-pick is commit.
The operation of git cherry-pick
-
single commit
git cherry-pick commit_id
-
Multiple consecutive commits are merged (excluding the beginning commit) intervals are left-closed and right-open
git cherry-pick commit_id1..commit_id100
Equivalent to
git cherry-pick (commit_id1..commit_id100]
-
Merge multiple contact commits (including the beginning commit)
git cherry-pick commit_id1^..commit_id100
-
Pick multiple commits
git cherry-pick <commit_id1> <commit_id2> <commit_id3>
Notice:
(1) The two dots in the middle indicate that all commits in the two commit intervals are copied over
(2) The string of 33ad206 is called the commit id. You can use the complete commit id, or you can intercept the part from the beginning, and make it as long as possible (unique).
code conflict
- resolve conflict
-
git add .
-
git cherry-pick -continue
This article is transferred from https://www.wujingquan.com/posts/e35b8a81.html
This site is only for collection, and the copyright belongs to the original author.