[Git] Let’s talk about the use of development and testing in Git & the usage scenarios of Git branches & Git tags

1. Introduction to the environment

  1. dev environment: Development environment, inaccessible to external users, used by developers, and the version changes greatly.
  2. test environment: Test environment, inaccessible to external users, specially used by testers, the version is relatively stable.
  3. pre environment: Grayscale environment, which can be accessed by external users, but the server configuration is relatively low, and everything else is the same as production.
  4. pro(master) environment: Production environment, an environment for external users, a formal environment that can be accessed by connecting to the Internet.

2. Git common application scenarios

In actual application scenarios, the use of Git for development and testing mainly includes the following aspects:

  1. Push local code snippets to the remote repository: Developers can develop and test code locally, and then submit it to the remote repository through Git so that others can view and share the code.
  2. Git version rollback: If there is a problem with the code of the current branch, you can find the previous correct version by checking the Git log and use git reset command to roll back to this version.
  3. Git branch switching: Developers can develop different functions or fix different bugs on different branches, and then merge the branches into the main branch after testing is completed.
  4. Git's tag application: When releasing software, you can create a tag for the current version to facilitate subsequent search and tracking.

3. Git branch

Regarding branches, Git supports create, switch and Merge branches. Create branch using git branch command, switch For branches use the git checkout command, and for merge branches use the git merge command. Branches can be used to develop new features or fix bugs without affecting the stability of the main branch.

1. What is the practical use of branches?

  1. Multi-person collaborative development: When carrying out multi-person collaborative development, in order to prevent mutual interference and improve the collaborative development experience, it is recommended that each developer develop project functions based on branches development.
  2. Function development: Since programmers cannot directly develop functions on the main branch, there is the concept of function branches. Feature branches can be used to manage and track code versions as milestones in the code base, marking the version of the code base at a specific point in time. This is useful for deploying, releasing, and rolling back code, as it ensures that the same version of the code is always used in the live environment.
  3. Continuous Integration/Continuous Deployment: In continuous integration or continuous deployment, branches are often used to isolate different versions of code. The master branch usually remains stable, while other branches are used for developing and testing new features or fixing bugs. This ensures the stability of the master branch while allowing other branches for frequent modification and testing.
  4. Version Control: Branching is an important part of version control. By using branches, code review and integration can be facilitated. Branches can also be used to manage versions of code in different development and collaboration environments to better track and manage code changes.

2. Common commands for Git branches

  1. git branch 分支名称: Create a new branch.
  2. git checkout -b 分支名称: Create a new branch and switch to the corresponding branch.
  3. git checkout 分支名称: Switch to the corresponding branch.
  4. git merge 分支名称: Merge the specified branch into the current branch.
  5. git cherry-pick 版本号: Merge a commit on the branch.
  6. git branch -d 分支名: Delete the remote branch.
  7. git fetch origin 分支名:<分支名>: Clone the remote branch to the local branch.
  8. git branch: View all branches

The ones we often use are create (git branch 分支名称), delete (), view (git branch ).git branch -d
分支名

3. Git branch usage scenarios

3.1. Local branch

Create a repository, create several new branches in it and switch.

Create a few new files inside to test the effects we want.

Add two files using the graphical interface of the GUI

You can see the two files we selected

After we commit using the dev branch, we switch our test branchtestYou can see that there are only unsubmitted ones left in our folder.

We cannot see the ask submitted by dev in other branches. If I want to see it, we need to use the command:git merge 分支名称Merge branches.

If there is a module (File 1) in our test that fails, we delete it in the folder and submit it again.

We switch to the master branch and merge the passed modules.

3.2. Remote branch

Push the branch we made locally.

git push origin branch name: Push the branch to git

Switching to our development branch, we can see that all our files are here and we are using the command to push.

We continue to push the branch of test.

4. Git tags

1. The actual use of Git tags

        tag is a way to mark historical versions of Git. You can create labels through the git tag command. The label name usually uses the "v version number ”, for example . Tags can be used to mark release versions of software to facilitate subsequent version management and tracking. v1.0

        Git tags are a convenient version marking method that can be used to record the software's release version, milestone, branch isolation version and Continuous integration/continuous deployment and other scenarios.

        The application scenario of Git tags is mainly used to mark specific versions and release information. The following are some common application scenarios of Git tags:

  1. Mark the released version of the software: When the software is released, you can use Git tags to mark the released version for subsequent tracking and search. Tag names usually take the form of "v version number", such as "v1.0".
  2. Record milestones of the code base: Git tags can be used to record important milestones of the code base, such as feature release, fixing a bug, etc. This makes it easy to backtrack to a specific codebase state and view the associated change history.
  3. Branch-isolated versions: In order to prevent mutual interference during multi-person collaborative development, Git tags can be used to mark versions of different branches. This makes it easy to find and merge code from different branches.
  4. Continuous Integration/Continuous Deployment: In continuous integration or continuous deployment, you can use Git tags to mark different versions of code for automated build and deployment. This ensures consistency of code versions in different environments.

2. Commonly used commands

  1. git tag <xxx>: Used to create a new label, the default is HEAD, you can also specify a commit id.
  2. git tag -a <xxx> -m "......": Specify label information.
  3. git tag: View all tags.
  4. git push origin <xxx>: Push a local tag.
  5. git push origin --tags: Push all local tags that have not been pushed before.
  6. git tag -d <xxx>: Delete a local label.
  7. git push origin :refs/tags/<xxx>: Delete a remote tag.

3. Usage scenarios

The methods used are basic and branching and there is nothing wrong with that.

We can see that we don't have a label.

We enter the corresponding branch, create a new tag, and push it.

We push multiple branches.

[Note] Our identification method is the suffix at the end. We use the suffix to identify the same version in different environments.

Guess you like

Origin blog.csdn.net/weixin_74383330/article/details/134350954
Recommended