一、使用场景
当我们需要将不同分支的代码进行合并的时候,就有两种情况。
1、合并所有代码(git merge)
2、合并部分代码(git cherry-pick)
二、基本语法
commit-hash为每次提交的记录值,可以通过git log origin/[branch] 进行查看
语法一
git cherry-pick [commit-hash] (合并单个提交)
git cherry-pick C
语法二
git cherry-pick [commit-hash1] [commit-hash2](合并多个提交)
git cherry-pick C D
语法三
git cherry-pick [commit-hash1]..[commit-hash2]
合并从commit-hash1到commit-hash2范围内的所有提交,但是这个是不包括commit-hash1
git cherry-pick B..D
语法四
git cherry-pick [commit-hash1]^..[commit-hash2]
合并从commit-hash1到commit-hash2范围内的所有提交,包括commit-hash1
git cherry-pick B^..D
三、GitDesk工具操作方法
需求:把main的部分commit合并到new-branch上去
第一步:进到main,选择需要合并的提交记录(可多选)
第二步:选择cherry-pick 2 commits...
第三步:选择new-branch,点击按钮进行合并
最后push到远程就行了