blog
blog copied to clipboard
聊聊 git cherry-pick
现在项目中维护的分支比较多,经常会遇到将A分支的某个提交记录合并到B分支的需求。最开始是单独提交两次到这两个分支,这种效率有些低,百度一搜发现有个git cherry-pick方法。
那git cherry-pick是什么东东?git cherry-pick可以理解为”挑拣”提交,它会获取某一个分支的单笔提交,并作为一个新的提交引入到你当前分支上。 当我们需要在本地合入其他分支的提交时,如果我们不想对整个分支进行合并,而是只想将某一次提交合入到本地当前分支上,那么就要使用git cherry-pick了。 具体使用命令:
git cherry-pick [<options>] <commit-ish>...
常用options:
--quit 退出当前的chery-pick序列
--continue 继续当前的chery-pick序列
--abort 取消当前的chery-pick序列,恢复当前分支
-n, --no-commit 不自动提交
-e, --edit 编辑提交信息
具体使用
git cherry-pick commit1
出现了错误
error: could not apply 233sdf...
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
找到冲突的文件,并解决。 解决完冲突后,执行以下命令:
git add .
git cherry-pick --continue
git push oringin master