git cherry-pick与git cherry命令详解

xiaoxiao2021-02-27  130

1.git cherry-pick,对当前分支apply已有的commits

特性:

对于给定的一个或多个已有的commits,在当前工作分支上,再次apply并生成新的commits当前工作分支必须是干净的,即HEAD不包含本地commits

使用:

git cherry-pick [--edit] [-n | --no-commit] [-m parent-number] [-s] [-x] [--ff] [-S[<keyid>]] <commit>…​

git cherry-pick --continue | --quit | --abort

选项说明:

--edit,编辑commit message-n, --no-commit,只是在当前分支上apply这些commits的改变,但是不提交到当前分支

示例:

git cherry-pick mastergit cherry-pick ..mastergit cherry-pick ^HEAD master

2.git cherry,查看当前分支及远程upstream之间commits的区别,给出是否applied

特性:

基于git diff,在<upstream>到<head>区间与<head>到<limit>区间比较commits输出结果为在<limit>和<head>区间内的所有commits的SHA-1列表 其中前缀-表示<upstream>中已apply其中前缀+表示<upstream>中未apply

使用:

git cherry [-v] [<upstream> [<head> [<limit>]]]

说明:

<upstream>默认为当前分支的HEAD对应的远程upstream分支<head>默认为当前分支的HEAD

示例:

git cherry origin/master topic base

参考文献:

https://git-scm.com/docs/git-cherry-pick

https://git-scm.com/docs/git-cherry

转载请注明原文地址: https://www.6miu.com/read-15572.html

最新回复(0)