当前位置:网站首页>How to use cherry pick?
How to use cherry pick?
2022-07-07 11:09:00 【Have a good time I】
Multi branch development , Then merge from the test branch to the production branch , Some content of the test branch will not be online this time , So it can't be full merge, How to operate at this time ?
You need to use git cherry-pick
The following is Ruan Yifeng's tutorial http://www.ruanyifeng.com/blog/2020/04/git-cherry-pick.html
For multi branch code bases , Moving code from one branch to another is a common requirement .
There are two situations . One situation is , You need all the code changes for the other branch , So take the merger (git merge). The other case is , You just need some code changes ( Some submit ), You can use Cherry pick.
One 、 Basic usage
git cherry-pick Role of command , Is to submit the specified (commit) Apply to other branches .
$ git cherry-pick
The above command will submit the specified to commitHash, Apply to current branch . This will generate a new commit in the current branch , Of course, their hash values will be different .
for instance , Code warehouse has master and feature Two branches .
a - b - c - d Master
\
e - f - g Feature
Will now submit f Applied to the master Branch .
# Switch to master Branch
$ git checkout master
# Cherry pick operation
$ git cherry-pick f
After the above operation is completed , The code base looks like this .
a - b - c - d - f Master
\
e - f - g Feature
You can see from above ,master A commit... Is added at the end of the branch f.
git cherry-pick Arguments to the command , Not necessarily the submitted hash value , Branch names are also OK , Represents the latest commit to transfer the branch .
$ git cherry-pick feature
The above code indicates that feature The last commit of the branch , Move to the current branch .
Two 、 Transfer multiple submissions
Cherry pick Support transferring multiple submissions at one time .
$ git cherry-pick <HashA> <HashB>
The order above will A and B Two commits are applied to the current branch . This will generate two corresponding new submissions in the current branch .
If you want to transfer a series of consecutive submissions , You can use the following simple syntax .
$ git cherry-pick A..B
The above command can be transferred from A To B All submissions for . They must be placed in the correct order : Submit A Must be submitted before B, Otherwise, the command will fail , But there is no error .
Be careful , Use the command above , Submit A Will not be included in Cherry pick in . If you want to include a submission A, You can use the following syntax .
$ git cherry-pick A^..B
3、 ... and 、 Configuration item
git cherry-pick Common configuration items of the command are as follows .
(1)-e,–edit
Open external editor , Edit submit information .
(2)-n,–no-commit
Update workspace and staging only , No new submissions .
(3)-x
Add a line to the end of the submission (cherry picked from commit …), It is convenient to find out how this submission is generated in the future .
(4)-s,–signoff
Add a line of operator's signature at the end of the submitted information , Indicates who performed the operation .
(5)-m parent-number,–mainline parent-number
If the original commit is a merge node , Merging from two branches , that Cherry pick Default will fail , Because it doesn't know which branch of code change to take .
-m Configuration items tell Git, Which branch changes should be used . Its parameters parent-number It is a slave. 1 The starting integer , Represents the parent branch number of the original submission .
$ git cherry-pick -m 1
The above command says ,Cherry pick Adopt submission commitHash From number 1 Changes in the parent branch of .
Generally speaking ,1 No. parent branch is the branch that accepts changes (the branch being merged into),2 Parent branch No. is the branch that is the source of the change (the branch being merged from).
Four 、 Code conflict
If there is a code conflict during the operation ,Cherry pick Will stop , Let the user decide how to proceed .
(1)–continue
After the user resolves the code conflict , The first step is to add the modified file back to the staging area (git add .), The second step is to use the following command , Give Way Cherry pick The process continues .
$ git cherry-pick --continue
(2)–abort
After a code conflict , Give up the merger , Back to what it was like before the operation .
(3)–quit
After a code conflict , sign out Cherry pick, But don't go back to what it was before .
5、 ... and 、 Move to another code base
Cherry pick It also supports the submission of transferring another code base , The method is to first add the library as a remote warehouse .
$ git remote add target git://gitUrl
The above command adds a remote warehouse target.
then , Grab the remote code to the local .
$ git fetch target
The above command grabs the remote code warehouse to the local .
next , Check the submissions to be transferred from the remote warehouse , Get its hash value .
$ git log target/master
Last , Use git cherry-pick Command transfer commit .
$ git cherry-pick <commitHash>
边栏推荐
- 关于jmeter中编写shell脚本json的应用
- Multithreaded application (thread pool, singleton mode)
- Mysql的json格式查询
- Is the gold content of intermediate e-commerce division in the soft exam high?
- Those confusing concepts (3): function and class
- 2021-04-23
- [pytorch 07] hands on deep learning chapter_ Preliminaries/ndarray exercises hands-on version
- Get pictures through opencv, change channels and save them
- Use load_ decathlon_ Datalist (Monai) fast loading JSON data
- uniapp 在onLaunch中跳轉頁面後,點擊事件失效解决方法
猜你喜欢
![[système recommandé 01] rechub](/img/92/c14c867247d3a042c69b5ed0091fbe.png)
[système recommandé 01] rechub

Ping tool ICMP message learning

【亲测可行】error while loading shared libraries的解决方案

从色情直播到直播电商

uniCloud

Qtcreator sets multiple qmake
![[OneNote] can't connect to the network and can't sync the problem](/img/28/9a02b1da0f43889989a9539c9fb6b6.png)
[OneNote] can't connect to the network and can't sync the problem

What are the contents of the intermediate soft test, the software designer test, and the test outline?

shardingsphere分库分表示例(逻辑表,真实表,绑定表,广播表,单表)

【推薦系統 01】Rechub
随机推荐
Ping tool ICMP message learning
Ffmpeg record a video command from RTSP
2021 summary and 2022 outlook
SQL Server knowledge collection 11: Constraints
单调性约束与反单调性约束的区别 monotonicity and anti-monotonicity constraint
Basic knowledge of process (orphan, zombie process)
Transaction rolled back because it has been marked as rollback-only解决
[untitled]
BUUCTF---Reverse---reverse1
长列表性能优化方案 memo
[machine learning 03] Lagrange multiplier method
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
【STM32】实战3.1—用STM32与TB6600驱动器驱动42步进电机(一)
Realize ray detection, drag the mouse to move the object and use the pulley to scale the object
Some online academic report websites and machine learning videos
uniapp 在onLaunch中跳转页面后,点击事件失效解决方法
VR development optimization
一些线上学术报告网站与机器学习视频
Is the gold content of intermediate e-commerce division in the soft exam high?
Unable to open kernel device '\.\vmcidev\vmx': operation completed successfully. Reboot after installing vmware workstation? Module "devicepoweron" failed to start. Failed to start the virtual machine