Use of version control system-------installation, local warehouse, remote warehouse, branch

Version control tool

Why learn version control tools?

1.1 Encountered a problem: When we implement a function, there are multiple implementation methods. It is possible that some codes that do not need to be used temporarily will have comments, but these comments will increase the size of the file, which is not conducive to user access speed.
1.2 Development In the project, it is usually developed by multiple people. How to solve the problem of code sharing?
If only the files are packaged and sent, it will be very inefficient.
Insert picture description here

Common version control tools

Git : The most advanced distributed version control system in the world.
svn : An older version control tool

Installation and configuration

1.1 Install
git official website installation: https://git-scm.com/download/win
1.2 Configure email and name The
first-time user needs to provide submitter information, and future development can be used to distinguish different modifiers

git config  --global user.name "自己的用记名"
git config  --global user.email "自己的正确的邮箱"

# 查看配置信息
git config --list

Local warehouse (work area)\temporary area\submission history

1.1 Warehouse initialization

Create a new folder as a warehouse
Method 1:
Open the folder with vscode, click Source Code Management, and initialize the repository: Any operation performed below needs to be based on a warehouse.
Insert picture description here
Method 2: Use the command line to
right-click the folder to open the control window and entergit init

git init

Insert picture description here
Indicates to initialize a Git warehouse. When the initialization is successful, a .gitfolder will be created in the root directory of the project. The folder is hidden, and you can see it by unhiding. It is used to manage the version information.
If you want to delete the warehouse, you only need to put the folder Delete the .git file

2. The area code works submitted to the staging area
to create a file within the folder, retrieved console input.
Add a single file: git add 文件名字;
the workspace all the files are added to the staging area: git add .;
staging area no physical file;
Insert picture description here
3. the staging area code is committed to the repository
complete statement: git commit --message "第一次提交";
short statement: git commit -m "第一次提交";
required property -m represents the record the information submitted, "" double quotes used to record information file, do not write without basis, there must be a semantic Change.
Insert picture description here

4. View submission history commands
Statement: git log
commit : indicates the submitted hash value, used to mark the uniqueness of the submission
Author: submitter information
Date : submission time
Insert picture description here
5. View file status
Statement: git status
he is used to view the work area and temporary storage area The status of the file. After
submission:
Insert picture description here
When there is still tracking status:
Insert picture description here
6. A more convenient way of submitting history, bypassing the temporary storage area and
directly submitting to the history from the work area
Statement:git commit -a -m"提交的信息"
Insert picture description here

Note: If it is a newly created file, the default status is untrackstatus, which means that the file has not been tracked. This is a quick command submission. If you need to submit a new file, you must first use the git addcommand to add it to the temporary storage area

7. View and modify files on the current version of a difference
statement: git diff;
mainly to see the difference not any historical submitted revised
Insert picture description here
8. rollback commit history (caution, not back!)
Syntax: git reset --hard 提交的哈希值;
note the space
-hard representation Modify the code of the work area directly. This parameter has other values, so no expansion is done here;
directly bypass the temporary storage area and roll back;
Insert picture description here

Remote warehouse

The registered historical information is stored locally, and for the convenience of development, it is generally pushed to remote warehouses.
Remote warehouse categories:
1. The world's largest code sharing platform github
Disadvantages: slow access
Advantages: resources are very rich, with the world's best code
2 .Domestic code hosting platform Code Cloud gitee
Disadvantages: relatively few projects
Advantages: fast access
3. Company-built code hosting (gitlab)
Disadvantages: inaccessible outside
Advantages: Security

Use
scenario 1 : The remote warehouse is not empty, by cloning the remote warehouse to the local

1. Clone the remote warehouse to the local.
Syntax: git clone 远程仓库地址
create a folder and enter in the console
Insert picture description here
2. Update the local warehouse.
Syntax: git pull
Unlike cloning, the clone is to move the entire warehouse down, and the pull is only to update.
3. Push the local code to the remote Warehouse
syntax:git push

Insert picture description here

Scenario 2 : The local warehouse is associated with an empty remote warehouse

Publish local warehouse to remote warehouse

1. Create a remote warehouse

2. Create a local warehouse and initialize

3. Generate a submission

4. The local repository associated with the remote warehouse
syntax: git remote add origin 远程仓库地址;

5. The native code pushed to the remote repository, because the remote warehouse is empty, you need to create a branch
syntax: git push -u origin master;

6. Review the current address of a remote repository repository
syntax: git remote -v;

Scenario 3 : If you modify the same file at the same time, there will be conflicts. The
solution to the conflicts: you need to solve them manually, select the code that needs to be retained

Branch management

What is a branch? It is
equivalent to an independent warehouse, and the work between each branch does not affect each other.

What problem does the branch solve? The
development of a version may have different functions, such as: registration/login/shopping cart/purchasing activities. When the deadline of the eleventh limit is reached, the function of the snap-purchase has not been developed. At this time, you can abandon the branch code of the snap-purchase activity , Directly go online to register/login/shopping cart.
Solve problems in multiple functional scenarios.

How to use branches?

1. Check the branch
syntax: git branch;
Generally, the warehouse has a default master branch, master,
do not submit code in the master branch!!!
Generally in the develop development branch, or fe/login
Insert picture description here

2. Create a branch
Create a branch, and switch to the branch name by the way.
Syntax 1: git checkout -b "名字"
Syntax 2: git branch"分支名字"
Both can be used
Insert picture description here

3. Switch branch
syntax:git checkout "分支名字"

4.Delete branch
syntax: git branch -D"分支名字"
pay attention to capitalization!
Insert picture description here

The combined branch
first switch to master
syntax: git merge 目标分支;

Summary

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_47886687/article/details/108808184