当前位置:   article > 正文

git cherry pick的使用教程_git cherry pick怎么用

git cherry pick怎么用


前言

对于多分支的代码库,往往需要切换不同分支。那么往往需要用到以下两个操作:
git merge (合并分支所有commit)
git cherry-pick (有选择的合并其他分支的commit)

基本用法

1.合并一个commit

指定commit用于其他分支。命令:

git cherry-pick <commitHash>
  • 1

例如:从icp3.6.0-b合并代码到icp3.6.0
查看icp3.6.0-b分支一个commitHash值
在这里插入图片描述
切换当前分支为icp3.6.0,执行如下命令:

git cherry-pick 6173278d...
  • 1

在这里插入图片描述
执行git push命令,提交代码

git push
  • 1

在这里插入图片描述
确认icp3.6.0分支代码是否合并成功
在这里插入图片描述

2.合并多个commit

#合并a和b,尖括号内为a和b两次commit对应的hash值
git cherry-pick <hash of a> <hash of b>
  • 1
  • 2

3.合并连续的多个commit

# 转移a到c所有commit,不包含a
git cherry-pick a..c
#转移a到c所有commit,包含a
git cherry-pick a^..c
  • 1
  • 2
  • 3
  • 4

4.git cherry-pick的帮助信息

>git cherry-pick -h
usage: git cherry-pick [<options>] <commit-ish>...
   or: git cherry-pick <subcommand>

    --quit                end revert or cherry-pick sequence
    --continue            resume revert or cherry-pick sequence
    --abort               cancel revert or cherry-pick sequence
    -n, --no-commit       don't automatically commit
    -e, --edit            edit the commit message
    -s, --signoff         add Signed-off-by:
    -m, --mainline <parent-number>
                          select mainline parent
    --rerere-autoupdate   update the index with reused conflict resolution if possible
    --strategy <strategy>
                          merge strategy
    -X, --strategy-option <option>
                          option for merge strategy
    -S, --gpg-sign[=<key-id>]
                          GPG sign commit
    -x                    append commit name
    --ff                  allow fast-forward
    --allow-empty         preserve initially empty commits
    --allow-empty-message
                          allow commits with empty messages
    --keep-redundant-commits
                          keep redundant, empty commi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

5.解决冲突

如果出现冲突,首先解决冲突文件,然后执行git add .
然后执行下面的命令:

git cherry-pick --continue
  • 1
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号