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如何将http访问的网站改成https访问
Mar 31 Servers
Windows下使用Nginx+Tomcat做负载均衡的完整步骤
Mar 31 Servers
nginx结合openssl实现https的方法
Jul 25 Servers
教你利用Nginx 服务搭建子域环境提升二维地图加载性能的步骤
Sep 25 Servers
Nginx实现负载均衡的项目实践
Mar 18 Servers
iSCSI服务器CHAP双向认证配置
Apr 01 Servers
Mac电脑OS系统下安装Nginx的详细教程
Apr 14 Servers
Windows和Linux上部署Golang并运行程序
Apr 22 Servers
Apache SeaTunnel实现 非CDC数据抽取
May 20 Servers
Apache POI操作批量导入MySQL数据库
Jun 21 Servers
Windows Server 修改远程桌面端口的实现
Jun 25 Servers
windows系统安装配置nginx环境
Jun 28 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
Smarty模板类内部原理实例分析
2019/07/03 PHP
php5.3/5.4/5.5/5.6/7常见新增特性汇总整理
2020/02/27 PHP
javascript使用eval或者new Function进行语法检查
2010/10/16 Javascript
利用jquery的获取JS文件中的字符串内容
2012/02/14 Javascript
Jquery实现页面加载时弹出对话框代码
2013/04/19 Javascript
js正则表达式的使用详解
2013/07/09 Javascript
jQuery实现预加载图片的方法
2015/03/17 Javascript
两种JS实现屏蔽鼠标右键的方法
2020/08/20 Javascript
AngularJS控制器controller正确的通信的方法
2016/01/25 Javascript
BootStrap glyphicon图标无法显示的解决方法
2016/09/06 Javascript
微信小程序 image组件binderror使用例子与js中的onerror区别
2017/02/15 Javascript
Underscore之Array_动力节点Java学院整理
2017/07/10 Javascript
利用Ionic2 + angular4实现一个地区选择组件
2017/07/27 Javascript
jsTree事件和交互以及插件plugins详解
2017/08/29 Javascript
JavaScript自执行函数和jQuery扩展方法详解
2017/10/27 jQuery
JS中的两种数据类型及实现引用类型的深拷贝的方法
2018/08/12 Javascript
electron-vue利用webpack打包实现多页面的入口文件问题
2019/05/12 Javascript
详解关闭令人抓狂的ESlint 语法检测配置方法
2019/10/28 Javascript
python简单实现获取当前时间
2016/08/27 Python
利用Opencv中Houghline方法实现直线检测
2018/02/11 Python
关于python3中setup.py小概念解析
2019/08/22 Python
Python matplotlib绘制图形实例(包括点,曲线,注释和箭头)
2020/04/17 Python
在echarts中图例legend和坐标系grid实现左右布局实例
2020/05/16 Python
解决Keras自带数据集与预训练model下载太慢问题
2020/06/12 Python
python 发送邮件的四种方法汇总
2020/12/02 Python
python 操作excel表格的方法
2020/12/05 Python
总裁岗位职责
2013/12/04 职场文书
奥巴马的演讲稿
2014/05/15 职场文书
俞敏洪北大演讲稿
2014/05/22 职场文书
投标人廉洁自律承诺书
2014/05/26 职场文书
房屋租房协议书范本
2014/12/04 职场文书
商务英语求职信范文
2015/03/19 职场文书
水知道答案观后感
2015/06/08 职场文书
pytorch中Schedule与warmup_steps的用法说明
2021/05/24 Python
python3+PyQt5+Qt Designer实现界面可视化
2021/06/10 Python
Python scrapy爬取起点中文网小说榜单
2021/06/13 Python