Front-end and back-end interaction: Git (branch)

2. Git Advanced

2.1, branch

For the sake of understanding, you can temporarily think of a branch as a copy of the code in the current working directory.

Using branches allows us to separate from the main line of development so as not to affect the main line of development.

2.1.1 What is a branch

  • In the version control process, multiple tasks are pushed forward at the same time. For each task, we can create a separate branch for each task.
  • Using branches means that programmers can separate their work from the main line of development, and when developing their own branches, it will not affect the operation of the main line branch
  • For beginners, a branch can be simply understood as a copy, and a branch is a separate copy

2.1.2 Branch Features

  • Simultaneously promote the development of multiple functions in parallel to improve development efficiency.
  • During the development process of each branch, if the development of a certain branch fails, it will not have any impact on other branches. Failed branches can be deleted and restarted.

2.1.3 Branch Subdivision

  1. Master branch (master): A branch that is automatically generated when the update record is submitted to the git warehouse for the first time.

  1. , Development branch (develop): As a development branch, it is created based on the master branch.

  1. Feature branch (feature): as a branch for developing specific functions, it is created based on the development branch

feature branch -> development branch -> master branch

2.1.4 Branch commands (all important)

command name effect
git branch view branch
git branch 分支名称 create branch
git checkout 分支名称 switch branch
git merge 来源分支 merge branch
git branch -d 分支名称 Delete branch (deletion is allowed after the branch is merged) (-D force delete)
1. View branch

Basic syntax:git branch -v

2. Create a branch

Basic syntax:git branch 分支名

3. Switch branches

Basic syntax:git checkout 分支名

4. Modify the files on the branch

5. Merge branches

Basic syntax:git merge 分支名

①Normal merge does not conflict

merge conflicts

Cause of conflict:

  • When merging branches, the two branches are inthe same location in the same fileThere are two completely different sets of modifications.
  • There are two completely different sets of modifications. Git can't decide which one to use for us. The new code content must be manually decided.

For example, we first modify the penultimate line of the master branch, add it to the temporary storage area, and then submit it to the local library

Solution: See 3.5 Resolving Conflicts for details

2.2, Temporarily save the changes

In git, all changes on the branch can be temporarily extracted and stored, allowing developers to get a clean working copy and temporarily turn to other work.

Usage scenario: branch temporary switching

  • Storing temporary changes:git stash
  • Revert changes:git stash pop

Guess you like

Origin blog.csdn.net/m0_55990909/article/details/124336846