Are you still using merge, learn about rebase

foreword

As the version management of our daily development code, Git plays a very important role in the management of development branches. In our development process, branches usually include production, pre-release, testing, and development. We will follow a certain stage of the project , submit the code to a certain version, the normal process is to develop first —> test —> pre-release —> production, but usually there are many versions, there is a sequence of online, and our developers will also be multiple, in Under various factors, the remote branch of the development version of the project and the local branch management of developers are the key.

General development process

There are several stages that a normal version needs to go through, namely dev, test, uat, and master. It is no problem for us to do this through the flow chart below. Each stage will branch the version pulled from the master and push it to the corresponding branch. The code of the normal pre-release and production environments should be consistent. Since the test branch will have multiple versions developed in parallel, the code will be slightly different from the pre-release and production.

B6C4A36C-1922-4B72-954E-414C41A8D7D5.png

Multi-version parallel development

When multiple versions are not developed, the management of branches is not as simple as above. Multiple versions are involved. The launch time nodes of these versions are also different, which means that the time nodes of test and uat are also different. .

There are many situations involved

  1. In the case of fewer back-end developers, usually 2-3 people as an example, it is completely possible to pull a development branch from the master. The branch format is the service name + online time, such as the local branch of xxx_20230130, and the back-end developers work together on this Parallel development is carried out on the branch. In the development stage, merge your own local branch to the dev branch. Because there are only 2-3 people, it is okay to resolve conflicts. If there are conflicts, resolve conflicts.
  2. When there are many back-end developers, usually 5-8 people as an example, at this time, the branch is pulled from the master branch, and the branch format needs to be named after the service name + initials + online time. In this way, during the local testing in the development stage, it can not affect each other, but when merging to the remote branch, you need to be more careful when resolving code conflicts. This kind of work should be left to careful people. Well, when testing, you also need to test according to the priority of the version launch.
  3. If there are many versions, for example, there will be 4-5 versions developed in a month, then the launch time is also divided into 4-5 nodes, so you need to merge the code to the next version from the remote branch that is launched first. on the local development branch of , and so on.

58C8F39E-4161-4FBA-9861-CF48E436F5AF.png

Git merge

As a command for git to merge branches, it is also a command that is often used in the daily development process. Usually, we will merge a version with the latest code to an older version to achieve version synchronization.

3EE8E0C2-67C1-4136-9703-67726D5B1005.png

It is roughly such a step, from the public branch at the beginning to the master and feature branches, and merge the master branch to the feature branch through the git merge master command. The Merge command will merge all the commit submissions of the previous featrue branch into a new commit submission. ⚠️Here only when there is a conflict can a new commit record be generated.

It can be understood as git pull = git fetch + git merge, pull the latest remote branch, and then merge this branch into another branch.

When the company is developing, usually everyone likes this command, because it is simple and rude, and it is simple and easy to understand by directly merging other branches into its own branch.

Git fox

As my personal preference, I prefer the rebase command, and the core concept is "rebase".

3F362A81-B158-4CCA-86A8-FA7715E2FDF7.png

  1. As can be seen from the figure above, the feature branch is extended to the back of the master branch through the reabse command.
  2. In the multi-person development process, if other people commit on the master, you submit several commits on the feature branch at this time. At this time, you use the rebase command to put your commit submission record behind the master's commit record. And merge will merge the commits of different branches into a new commit record, which is the difference between merge and rebase.
  3. If the local feature branch and the remote master branch are the same branch, rebase can be used to ensure the clarity of the commit record, which is very important!

⚠️Do not use the rebase command on the public branch, as this will pollute the public branch, so your commit record will exist in the public branch, and your latest commit record will exist when others pull it.

Summarize

In development, not only high code quality is required, but version management is also very important. I believe everyone has encountered the problem of missing code before going online, but this kind of thing is very dangerous ⚠️, I hope this article can give Everyone submits vigilance in daily code version management, and merges branches reasonably. Finally, I wish you less bugs, more learning, and more progress in the new year.

Guess you like

Origin juejin.im/post/7192823689426468919