当前位置:网站首页>Git rebase is in trouble. What to do? Waiting line
Git rebase is in trouble. What to do? Waiting line
2020-11-06 20:33:00 【itread01】
We are using git Have you ever made a mistake in the process of ?
I've been through , My first disaster was the use of git rebase Caused by the , Although it was finally solved , But it still scares me a lot . It was like this .
Let's take a look at this picture :
![](http://inotgo.com/imagesLocal/202011/06/20201106203331569w_1.jpg)
Briefly explain what's in this picture ,C1 Nodes are the smallest common ancestor of all branches . It can be understood as the earliest master edition , And then we checkout Two branches came out , The difference is bugFix and feature. among feature It's a new branch of our development , and bugFix It's repairing bug The branch of .
When we put bugFix After that, hurry up merge master Released , When we released it, we found bugFix There's a little bit of a problem . For example, the file that should not be submitted has been submitted , Plus, we don't use rebase Combined in the form of , So it looks like commit The records are a little messy . So I decided to use rebase Fix the submission record , Use when you're done git push -f Forced update of remote branch .
Because we've been push After , Want to use a new commit If the record covers the old, it must be used -f Push... By force . These operations are routine operations , But I accidentally made a big problem , Almost led to the tragedy later .
I'll sell you something first , Let's think about it for a few seconds , What's the hidden question here ?
rebase The taboo of
The problem here is feature Branch , We can see from the picture that feature Branch is merge 了 C5 Node's . But when we rebase push -f After that ,C5 Nodes don't exist . Let's show you the pictures and you will understand , This is rebase The previous dependency tree :
![](http://inotgo.com/imagesLocal/202011/06/20201106203331569w_0.jpg)
We rebase And then the dependency tree became like this :
![](http://inotgo.com/imagesLocal/202011/06/20201106203331569w_2.jpg)
Because of feature I used to merge Over master And rely on C5 Node , and master stay rebase Force push After that, there is no more in the whole link C5 Node . That is to say feature The branch depends on a node that no longer exists , It's not too bad at this time , Because feature The branch hasn't been updated yet , If feature Branch pull once , Then the whole branch will be like this :
![](http://inotgo.com/imagesLocal/202011/06/20201106203331569w_4.jpg)
That is to say, the same code is in feature Two versions are stored in the branch , And if feature Merge into master After that , You'll find out before push -f Those submissions that were forced to abandon were merged again , And the whole thing commit Of log It's going to be very, very chaotic , It's hard to understand .
If these branches are their own , Then if you pinch your nose , If these branches belong to someone else in the team , It's basically unavoidable to make a mess . If there is one in the group Git The boss knows how to solve this situation. It's OK , Otherwise , It's very difficult to recover completely , It's very likely that one operation has no idea where the deviation is , I don't know how to find it back .
I was fine , I have learned how to deal with this situation when I make trouble , Although still can't avoid stepping on the pit , But fortunately, I came out of the pit in time . Before we look at the method of debonding , Let's start with a question , For rebase What is the root cause of the chaos , How can we avoid ?
To solve rebase Only rebase
Why did we just C8 Once the node pull It will lead to local chaos ? Because we've introduced , When we execute pull When , In fact, it was carried out git fetch and git merge Two steps . So it is equivalent to that we put master The change of the branch merge Once , We depend on rebase Previous changes , Such a merge Naturally, the two versions will be changed merge Together .
To solve this problem , We can't be in C8 Node time pull operation , Because pull Operation contains merge,merge It can lead to mistakes . It is not difficult to solve this problem , We can rebase To master On . When we execute rebase When ,git Will find out that our current branch is unique and master There's no change on the branch , Extract these changes and apply them to master We got a new result on .
![](http://inotgo.com/imagesLocal/202011/06/20201106203331569w_3.jpg)
So we don't put... In our records C2 and C5 Brought in .
Divergent thinking
Let's think through the above process , What's the conclusion ?
In fact, the conclusion is very simple , Namely rebase Although it's very easy to use, it's also very convenient , But it also has conditions that apply , The biggest condition is that if there are other branches that depend on the current branch , We can't use it at this time rebase, Otherwise, it will cause confusion .
What is the cause of the confusion ? It's essentially us rebase It's time to change commit The record of , Different people have different opinions on this point . There is a group of people who think git You can't tamper with your submission records , The purpose of its existence is to record repo All the changes that have taken place . If you use rebase And so on , Then we can't trace the changes and versions well . There's another person who doesn't think so , They feel that if the change of the record is very confusing, it is very inconvenient for users to read , At this time, it is very necessary to use some methods to repair it . Tools are invented for use .
The two parties are arguing endlessly , Different people have different views , It can be said that it is a problem of values, and it is not too much . I personally prefer the latter on this issue , Since there is such a good tool , Nature should use . Use is not abuse , We need to follow certain rules , It's the only way to make sure you don't make a mess of it . For example, it must not be used when there are other downstream dependencies rebase, Otherwise, it is almost certain that it will cause trouble .
Today's article is here , I wish you every day something to gain . If you still like today's content , A third company, please ~( Like it 、 Concern 、 Forward )
Link to the original text , Seeking attention
This article USES the mdnice Typesetting
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
边栏推荐
- 【转发】查看lua中userdata的方法
- EOS founder BM: what's the difference between UE, UBI and URI?
- Flink的DataSource三部曲之一:直接API
- Helping financial technology innovation and development, atfx is at the forefront of the industry
- Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
- The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
- 視覺滾動[反差美]
- The AI method put forward by China has more and more influence. Tianda et al. Mined the development law of AI from a large number of literatures
- C#和C/C++混合编程系列5-内存管理之GC协同
- Swagger 3.0 brushes the screen every day. Does it really smell good?
猜你喜欢
What course of artificial intelligence? Will it replace human work?
[Xinge education] poor learning host computer series -- building step 7 Simulation Environment
2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办
Behind the first lane level navigation in the industry
It is really necessary to build a distributed ID generation service
Ronglian completed US $125 million f round financing
What are the criteria for selecting a cluster server?
【自学unity2d传奇游戏开发】如何让角色动起来
It's easy to operate. ThreadLocal can also be used as a cache
【ElasticSearch搜索引擎】
随机推荐
Introduction to X Window System
01. SSH Remote terminal and websocket of go language
CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
【转发】查看lua中userdata的方法
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
Named entity recognition in natural language processing: tanford core LP ner (1)
【ElasticSearch搜索引擎】
前端未來趨勢之原生API:Web Components
华为云微认证考试简介
How to turn data into assets? Attracting data scientists
Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
Using NLP and ml to extract and construct web data
Introduction to the structure of PDF417 bar code system
Introduction to Google software testing
Flink的DataSource三部曲之一:直接API
Humor: hacker programming is actually similar to machine learning!
文件过多时ls命令为什么会卡住?