当前位置:网站首页>The problem that Merge will be lost again after code Revert has been solved
The problem that Merge will be lost again after code Revert has been solved
2022-08-11 02:55:00 【Java Punk】
1. Problem scene
The premise is that my company uses GitLab for code management.
This exception occurred during a regular iterative upgrade of the system not long ago. Due to a problem with the third-party package that the system depends on, the service could not be started. In order not to affect the use of other functions, the master branch wasDo a revert to the last version.
When we solved the problem of dependent packages and re-applied the merge application from dev to master, we found that the code changes were not displayed (Note: If the code is modified, there may also be a "conflict" problem, butEssentially the same), making it impossible to merge branches.That is: the rolled-back code is considered to already exist on the master branch and is not considered a change.
II. Reason analysis
The revert operation is actually just a reverse commit to roll back the merge code, but the commit record still exists.That is to say, the code to be submitted that exists on the dev is actually the past code of the master, which belongs to the state that has been submitted, so it will not display different.
Third, the solution
Option 1: Officially recommended method
The core idea is: revert the commit record that was reverted again.
- First, switch to the master branch and pull a branch revert_tmp based on the master branch.As a copy of master, the role of revert_tmp is to save the commit record of revert;
git checkout mastergit checkout -b revert_tmp
- Secondly, find the version number of the commit record of revert on the master branch, and roll back to the previous version (the version number can be viewed through the "git log" command or from the web page);
git log # Query , format, such as: f2c3b544166eec612ea6814d6cd19aeef46824f8git revert
- Then, switch to the dev branch and merge the revert_tmp branch to the dev branch.
git checkout devgit merge revert_tmpgit push -f
- Finally, resubmit the merge application to master in dev, and you will find that the code before revert is back.
Option 2: reset method
Unlike revert, using -- git reset to move head backward to the commit version before the last merge will discard all merge commit records (revert will not discard it, it is a reverse commit), so merging again will notThere is a problem that records are not displayed or conflicted.
git reset HEAD^ # Roll back everything to the previous versiongit reset HEAD^^ # Roll back everything to the previous version
Note: Use the --hard parameter with caution, it deletes all information up to the fallback point.
HEAD Description:
–hard parameter | Parameter description |
---|---|
HEAD | represents the current version |
HEAD^ | Previous Version |
HEAD^^ | Previous Version |
HEAD^^^ | Last previous version |
And so on... | |
^ can use ~numbers | |
HEAD~0 | represents the current version |
HEAD~1 | Previous Version |
HEAD~2 | Previous Version |
HEAD~3 | Last previous version |
And so on.. |
Summary
- It is recommended to use the official method - revert, which will not delete the version record;
- Article reference: Two methods for Git to restore previous versions reset, revert
边栏推荐
猜你喜欢
言简意赅,说说 @Transactional 在项目中的使用
ES进阶 数组功能语法新特性详解
A Practical Arrangement of Map GIS Development Matters (Part 1)
Summary of Logstash log data write exception troubleshooting
【DB运营管理/开发解决方案】上海道宁为您提供提高工作便利性的集成开发工具——Orange
Realization of vending machine function based on FPGA state machine
TRCX: doping process analysis
How to solve the problem of Tomcat booting and crashing
Js prototype and prototype chain and prototype inheritance
多线程之ThreadPoolExecutor
随机推荐
学军中学推理社2017届招新试题
BUU刷题记录
Detailed explanation of new features of ES advanced array function syntax
YTU 2418: C语言习题 矩阵元素变换
2022年G1工业锅炉司炉题库及模拟考试
掌握这几招,轻松K.O面试官,Offer拿到吐
this question in js
A practice arrangement about map GIS (below) GIS practice of Redis
Deep Learning - Second Time
Goodbye Guangzhou paper invoices!The issuance of electronic invoices for accommodation fees will completely replace the invoices of hotels, restaurants and gas stations
AI+医疗:使用神经网络进行医学影像识别分析
WeChat public account background management
自动生成数据库设计文档利器
GBJ3510-ASEMI家电电源用整流桥GBJ3510
comp3331-9331-21t1-midterm复习
[4G/5G/6G专题基础-154]: 5G无线准入控制RAC(Radio Admission Control)
ARM development (4) How to read the chip manual for novice Xiaobai, bare metal driver development steps and pure assembly to achieve lighting, assembly combined with c lighting, c to achieve lighting
The practice of alibaba data synchronization component canal
ES6进阶 字符串处理新特性
基于FPGA状态机的自动售货机功能实现