「GIT」- cherry-pick

cherry-pick

Intro to Cherry Picking with Git
git – How to copy commits from one branch to another? – Stack Overflow

当我们需要在本地合入其他分支的提交时,如果我们不想对整个分支进行合并,而是只想将某一次提交合入到本地当前分支上。那么就要使用 git cherry-pick 命令。

将其理解为”挑拣”提交,它会获取某一个分支的单笔 / 多笔提交,并作为一个新的提交引入到当前分支上。即,其将指定的提交从一个分支复制到另一个分支,但其它不会整合整个分支,而是只选择特定的提交。

# ----------------------------------------------------------------------------- # 选取单个提交

git cherry-pick <CommitID> 

git checkout "target-branch" # 从其他分支选取最后一个提交

# ----------------------------------------------------------------------------- # 选取多个提交

git cherry-pick <Commit ID 0> <Commit ID 1 > <Commit ID 2> 

git cherry-pick abc123..def456 # 选取一个范围内的提交(不包含起始提交)

git cherry-pick abc123^..def456 # 选取一个范围内的提交(包含起始提交)

  • –no-commit # 应用更改但暂不提交,方便进一步修改
  • -e # 在提交前编辑提交信息

冲突处理

git cherry-pick-CSDN 博客

git add .
git commit
git cherry-pick --continue
git push origin HEAD:refs/for/ 远程分支名