git cherry-pick 摘樱桃
cherry pick 英语摘樱桃,取这个名字的人,一定很喜欢樱桃。git的分支就像一樱桃树,commit就像樱桃。摘樱桃就像是把另一个分支的樱桃摘(实际是克隆)过来变成自己的樱桃。如果工作区不干净,会报:error: Your local changes to the following files would be overwritten by merge如果缓存区不干净,会报:error:
cherry pick 英语摘樱桃,取这个名字的人,一定很喜欢樱桃。
git的分支就像一樱桃树,commit就像樱桃。摘樱桃就像是把另一个分支的樱桃摘(实际是copy)过来变成自己的樱桃。
下面演示怎么摘,有两个分支分别是A和B,B有一个樱桃(4391e824)是A没有的。现在把它摘过来。
Administrator@OS-20201115UTAW MINGW64 /e/th/jk (A)
$ git log -2 --oneline
fab2d700 (HEAD -> A, origin/feature/xj1.7.0-137475, c137) 用户情景 137475: app新增线路画像功能模块
18d95437 同步统推v5.0.1新增巡视
Administrator@OS-20201115UTAW MINGW64 /e/th/jk (B)
$ git log -2 --oneline
4391e824 (HEAD -> B, c123) c p
fab2d700 (origin/feature/xj1.7.0-137475, c137, A) 用户情景 137475: app新增线路画像功能模块
Administrator@OS-20201115UTAW MINGW64 /e/th/jk (A)
$ git cherry-pick B 4391e824
[A eb5291df] c p
Date: Mon May 17 09:29:41 2021 +0800
1 file changed, 3 insertions(+), 1 deletion(-)
Administrator@OS-20201115UTAW MINGW64 /e/th/jk-th-prssface-appWebNew (A)
$ git log -2 --oneline
eb5291df (HEAD -> A) c p
fab2d700 (origin/feature/xj1.7.0-137475, c137) 用户情景 137475: app新增线路画像功能模块
A把樱桃摘过来后,变成一自己的樱桃(eb5291df)。
cherry-pick与merge的区别:
如果两个分支已经独立变化很久了,暂时或长期都不可以合并,但A分支需要B分支其中的一个(或一些)樱桃就可以使用cherry-pick。使用cherry-pick避免了只需要部分,却要全部合并的尴尬。
cherry-pick之前需要B分支工作区和缓存区是干净的,否则会报错:
- 如果工作区不干净,会报error: Your local changes to the following files would be overwritten by merge
- 如果缓存区不干净,会报error: your local changes would be overwritten by cherry-pick
cherry-pick之后,如果代码有冲突,会报error: could not apply 4391e824... c p。分支会处于采摘中(cherry-picking)状态:
Administrator@OS-20201115UTAW MINGW64 /e/th/jk (r1.7.0)
$ git cherry-pick B 4391e824
Auto-merging src/ini.properties
CONFLICT (content): Merge conflict in src/ini.properties
error: could not apply 4391e824... c p
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'
Administrator@OS-20201115UTAW MINGW64 /e/th/jk (r1.7.0|CHERRY-PICKING)
当前处于采摘中状态,你还继续采摘下一个,会报error: cherry-pick is already in progress
结束采摘中状态可以用下面四个动作:
--continue 继续
处理完冲突的代码之后,可以使用此选项,结束采摘,继续下一个采摘
--skip 跳过
跳过这次采摘,不留痕迹,跟采摘之前一样。
--quit 退出
冲突还在,没有解决,结束了采摘中状态。强行结束了采摘动作。
--abort 中止
中止并取消摘过来的樱桃。也就是撤消采摘动作。
更多推荐
所有评论(0)