Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the changing Base Mode of Git

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

For this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Today, I am mainly chatting with everyone about GIT's rebase.

GIT itself for some beginners do not understand so well, for me, at the beginning of some basic concepts in the first contact, can not fully understand, only when these concepts into practice to form their own understanding, can know the original meaning of this concept, and this command is like this.

1. What is rebase

Change the base, we can understand the meaning of the base low. Just like building a building, there are layers of upward cover, and at the bottom is the foundation, and we call each layer of the cover the foundation.

(for a better understanding, take the above building as an example)

If, our floor has been built, a total of 18 floors, we need a number of decorators to decorate each floor. There are three people in my decoration team, which are A, B and C.

An is responsible for the first floor, B is responsible for the second floor, and C is responsible for the third floor. According to normal logic, three people who finish decorating their own floor ahead of time will go to the fourth floor to decorate.

But there is a problem is that if the second floor of B is also finished, but B does not know the latest progress of the other two people, so it needs to update its current progress to the latest in some way (B should know which floor to decorate next) in order to continue to decorate on the basis of the progress of the other two people.

Although the above example of building is not quite in line with the use of GIT in the project, in order to give everyone a general impression.

2. Why change the base?

In general, we work together to use GIT version control, and everyone develops on their own branch, and finally the person in charge can merge (merge) the branch developed by each person into the main branch. What is the use of changing the base mode?

First, the project gets bigger, the team has more people, more and more branches are submitted, and everyone has to be merged into the main branch after commit. The whole git branch diagram looks bad, which is not conducive to maintenance and management. (as shown above)

Second, the project is full of all kinds of commit, if one day, there is an emergency, need to roll back the code, found that this large number of commit need to look at one by one, let you see doubt life.

The above two reasons allow me to give up the traditional commit merge, and the code submitted using the base-changing mode is particularly clear. (as shown below)

3. How to change the base?

For how to change the base, the most important thing in this part is to practice, practice. If there is no practice, it will be in vain even if you read it. Remember what I said.

Change the base mode, using the following commonly used commands, or take the above building as an example.

When the second layer of B is finished, it wants to know the following development progress, and then proceed to the next development on the basis of everyone's progress.

Just like in a project, I have to submit the functionality I have developed, but when I develop the current functionality, someone else in the remote warehouse may have submitted the code, resulting in a code inconsistency between my local warehouse and the remote warehouse.

To be consistent with the remote repository code before the push code, we need to rebase (change the base) with the following command:

1git pull base dev-rebase

The equivalent of this order, B went directly to the fifth floor to decorate. And our decoration record, that is, the main branch of our development has become very clear and clear, that is, a branch line full of commit.

4. I changed my base when I was broken.

But the problem is that when I first used the GIT base-changing mode, I broke it many times and summed up some experience.

Every time I submit the latest code, I forget rebase, that is, every time I don't take into account the latest remote code, but instead develop the functionality and submit it directly, resulting in bifurcations in the online code (actually back to the original submission mode).

I'm in a hurry. What should I do? There's nothing wrong with the boss, one for two.

Use rollback and pick so that the main branch no longer bifurcates. The so-called pick is to use the cherry-pick command to re-mount the commit submission to the branch you want to mount.

1git cherry-pick

When you have finished pick, re-do push and pr, and the bifurcated branches return to the original line. Is it very nice?

This is the answer to the question about how to understand the Git base mode. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report