git中cherry-pick命令的使用教程


Posted in Servers onJune 25, 2022

git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作。例如,假设我们有个稳定版本的分支,叫v2.0,另外还有个开发版本的分支v3.0,我们不能直接把两个分支合并,这样会导致稳定版本混乱,但是又想增加一个v3.0中的功能到v2.0中,这里就可以使用cherry-pick了,其实也就是对已经存在的commit 进行再次提交。

简单用法:

git cherry-pick <commit id>

例如:

$ git checkout v2.0分支
$ git cherry-pick 38361a55 # 这个 38361a55 号码,位于v3.0分支中:

$ git log
commit 38361a55138140827b31b72f8bbfd88b3705d77a
Author: Justin Justin@xxx.com
Date: Sat Dec 10 00:11:44 2016 +0800

1. 如果顺利,就会正常提交。结果:

Finished one cherry-pick.
On branch v2.0分支
Your branch is ahead of 'origin/old_cc' by 3 commits.

2. 如果在cherry-pick 的过程中出现了冲突

Automatic cherry-pick failed.
After resolving the conflicts,mark the corrected paths with 'git add <paths>' or 'git rm <paths>'and commit the result with:
git commit -c 15a2b6c61927e5aed6111de89ad9dafba939a90b

或者:

error: could not apply 0549563... dev
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'

就跟普通的冲突一样,手工解决:

2.1 $ git status # 看哪些文件出现冲突

both modified: app/models/MainActivity.java

2.2 $ vim app/models/MainActivity.java # 手动解决它。

2.3 $ git add app/models/MainActivity.java

2.4 git commit -c <新的commit号码>

2.5 再次cherry-pick剩余commit

若提示:

error: a cherry-pick or revert is already in progress
hint: try "git cherry-pick (--continue | --quit | --abort)"
fatal: cherry-pick failed

则执行对应操作:

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

命令集合:

git cherry-pick <commit id>:单独合并一个提交
git cherry-pick -x <commit id>:同上,不同点:保留原提交者信息。
Git从1.7.2版本开始支持批量cherry-pick,就是一次可以cherry-pick一个区间的commit。
git cherry-pick <start-commit-id>..<end-commit-id>
git cherry-pick <start-commit-id>^..<end-commit-id>

前者表示把<start-commit-id>到<end-commit-id>之间(左开右闭,不包含start-commit-id)的提交cherry-pick到当前分支;
后者有"^"标志的表示把<start-commit-id>到<end-commit-id>之间(闭区间,包含start-commit-id)的提交cherry-pick到当前分支。
其中,<start-commit-id>到<end-commit-id>只需要commit-id的前6位即可,并且<start-commit-id>在时间上必须早于<end-commit-id>
注:以上合并,需要手动push代码。

以上内容总结如下:

1.git checkout master            //此操作需要切换到master分支  

2.git pull

3.git cherry-pick  xxxxxx
 
4.git status 
 
5.编译提交等

到此这篇关于git中cherry-pick命令的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。


Tags in this post...

Servers 相关文章推荐
解决Nginx 配置 proxy_pass 后 返回404问题
Mar 31 Servers
nginx安装以及配置的详细过程记录
Sep 15 Servers
nginx内存池源码解析
Nov 20 Servers
OpenStack虚拟机快照和增量备份实现方法
Apr 04 Servers
CentOS7和8下安装Maven3.8.4
Apr 07 Servers
在Windows Server 2012上安装 .NET Framework 3.5 所遇到的问题
Apr 29 Servers
Win10 Anaconda安装python-pcl
Apr 29 Servers
阿里云服务器部署RabbitMQ集群的详细教程
Jun 01 Servers
django项目、vue项目部署云服务器的详细过程
Jul 23 Servers
windows10 家庭版下FTP服务器搭建教程
Aug 05 Servers
CentOS7设置ssh服务以及端口修改方式
Dec 24 Servers
keepalived + nginx 实现高可用方案
Dec 24 Servers
解决Git推送错误non-fast-forward的方法
Jun 25 #Servers
Win2008系统搭建DHCP服务器
windows server2008 开启端口的实现方法
Windows10安装Apache2.4的方法步骤
Linux下搭建SFTP服务器的命令详解
Jun 25 #Servers
Nginx安装配置详解
win sever 2022如何占用操作主机角色
Jun 25 #Servers
You might like
PHP中使用memcache存储session的三种配置方法
2014/04/05 PHP
php生成4位数字验证码的实现代码
2015/11/23 PHP
ThinkPHP框架搭建及常见问题(XAMPP安装失败、Apache/MySQL启动失败)
2016/04/15 PHP
PHP设计模式之工厂模式详解
2017/10/24 PHP
JQuery.closest(),parent(),parents()寻找父结点
2012/02/17 Javascript
使用javascript实现json数据以csv格式下载
2015/01/09 Javascript
微信JSSDK上传图片
2015/08/23 Javascript
如何实现移动端浏览器不显示 pc 端的广告
2015/10/15 Javascript
js父页面中使用子页面的方法
2016/01/09 Javascript
基于JS实现checkbox全选功能实例代码
2016/10/31 Javascript
Vue.js手风琴菜单组件开发实例
2017/05/16 Javascript
JavaScript对象拷贝与Object.assign用法实例分析
2018/06/20 Javascript
JavaScript创建对象的常用方式总结
2018/08/10 Javascript
详解Vue CLI3 多页应用实践和源码设计
2018/08/30 Javascript
JS立即执行的匿名函数用法分析
2019/11/04 Javascript
OpenLayers3实现对地图的基本操作
2020/09/28 Javascript
Vue 列表页带参数进详情页的操作(router-link)
2020/11/13 Javascript
python删除指定类型(或非指定)的文件实例详解
2015/07/06 Python
实践Python的爬虫框架Scrapy来抓取豆瓣电影TOP250
2016/01/20 Python
在Ubuntu系统下安装使用Python的GUI工具wxPython
2016/02/18 Python
Python实现的读取/更改/写入xml文件操作示例
2018/08/30 Python
浅谈django的render函数的参数问题
2018/10/16 Python
python tkinter实现屏保程序
2019/07/30 Python
python利用openpyxl拆分多个工作表的工作簿的方法
2019/09/27 Python
Pycharm远程连接服务器并实现代码同步上传更新功能
2020/02/25 Python
基于pytorch中的Sequential用法说明
2020/06/24 Python
scrapy结合selenium解析动态页面的实现
2020/09/28 Python
python 基于opencv实现高斯平滑
2020/12/18 Python
css3使用animation属性实现炫酷效果(推荐)
2020/02/04 HTML / CSS
HTML5+CSS3绘制锯齿状的矩形
2016/03/01 HTML / CSS
教师先进工作者事迹材料
2014/05/01 职场文书
心理咨询专业自荐信
2014/07/07 职场文书
餐饮店长岗位职责
2015/04/14 职场文书
预备党员转正意见
2015/06/01 职场文书
律政俏佳人观后感
2015/06/09 职场文书
Python 中的Sympy详细使用
2021/08/07 Python