[Project Issue] git cherry-pick selectively merges branches

1. Usage scenarios

When we need to merge code from different branches, there are two situations.
1、合并所有代码(git merge)
2、合并部分代码(git cherry-pick)

2. Basic grammar

Insert image description here

commit-hash is the record value of each submission, which can be viewed through git log origin/[branch]
Insert image description here

Grammar 1

git cherry-pick [commit-hash] (合并单个提交)

git cherry-pick C

Insert image description here

Grammar 2

git cherry-pick [commit-hash1] [commit-hash2](合并多个提交)

git cherry-pick C D

Insert image description here

Grammar three

git cherry-pick [commit-hash1]..[commit-hash2]
Merge all commits in the range from commit-hash1 to commit-hash2, but this does not include commit-hash1

git cherry-pick B..D

Insert image description here

Grammar 4

git cherry-pick [commit-hash1]^..[commit-hash2]
Merge all commits in the range from commit-hash1 to commit-hash2, including commit-hash1

git cherry-pick B^..D

Insert image description here

3. GitDesk tool operation method

Requirement: Merge some commits of main into new-branch

第一步:进到main,选择需要合并的提交记录(可多选)
Insert image description here
第二步:选择cherry-pick 2 commits...
Insert image description here
第三步:选择new-branch,点击按钮进行合并
Insert image description here
最后push到远程就行了

Guess you like

Origin blog.csdn.net/weixin_46318413/article/details/129690442