- Directory flow chart
1. Distributed version control and centralized version control
1.1 Centralized version control
- Centralized version control systems include: CVS and SVN
- Their main feature is a single centrally managed server that holds revisions of all files;
- Collaborative developers connect to this server through the client and retrieve the latest files or submit updates.
- Advantages and Disadvantages
- Compared to old-fashioned local management, everyone can see what everyone else on the project is doing to a certain extent.
- But centralized version control also has a core problem: the central server cannot fail:
- If the disk where the central database is located is damaged and proper backup is not done, you will undoubtedly lose all data;
1.2 Distributed version control
- Distributed version control systems include: Git
- Advantages and Disadvantages:
- The client does not only extract the latest version of the file snapshot, but completely mirrors the code warehouse, including the complete history;
- In this way, if any server used for collaborative work fails, any mirrored local warehouse can be used to recover afterwards;
- Because every cloning operation is actually a complete backup of the code repository ;
2. Installation and configuration
Installation and configuration reference
- Username and email configuration
$ git config --global user.name "username"
$ git config --global user.email "[email protected]"
3. git command line operations
Basic instruction premise
1. 克隆项目 `git clone 项目地址`
2. 初始化仓库` git init`
3. 添加暂存区 `git add .`
4. 提交本地仓库 `git commit -m 项目初始化`
5. master分支创建release分支` git branch release`
6. 基于master分支创建develop分支 `git branch develop`
# 推送master分支
git push -u origin master
# 推送release分支
git push origin release
# 推送develop分支
git push origin develop
# 在任意目录操作 (仓库地址仅供参考)
git clone https://gitee.com/zd1231230/doctor-demo.git
# 拉取其他分支
git fetch 项目地址 分支名称:别名
git fetch https://gitee.com/zd1231230/doctor-demo.git drugPayment:drugPayment
3.1 ADMU logo
M modified
You have added the file to github, and then if you modify the file, it will be marked with M after the file.
U untracked
If you create this file locally and haven't submitted it to github, it will be marked UD delete
If you delete this file, vscode-git will record this statusA
It has not been submitted yet in the staging area.
3.2 Basic commands for project initialization and submission
- Create an empty directory (preferably not containing Chinese)
$ mkdir gitMaster
$ cd gitMaster
$ pwd
/Users/git/gitMaster
- Initialize warehouse
git init
$ git init
Initialized empty Git repository in /Users/hxk/mymenu/.git/
- Add files to the repository
$ git add test.txt
- Submit files to the warehouse
- m
Following are the submission instructions- The submitted remark is wrong, you can use
git commit --amend
to modify it
$ git commit -m "a new file"
- View commit history
git log
- View status
$ git status
3.3 File status tracking and operation process
-
跟踪和未跟踪
Files can be divided into statuses when submitted未跟踪
: By default, files under the Git warehouse are not added to Git warehouse management. We need to operate through the add command;已跟踪
: Files added to Git warehouse management are in a tracked state, and Git can perform various tracking and management on them;
-
Check the status of a file
git status –s
git status --short
- Tracked files can be divided into subdivision statuses
staged
: File status in the buffer area;Unmodified
:commit command, you can submit staged files to the Git repositoryModified
: After a file is modified, it will be in Modified state;
- Command trace files
git add .
and add them to the staging area
- File Update Submission –
git commit - m
Submission Instructions
3.4 Submission history and version rollback
git log // 提交的日志 (里面包含提交的id) q 退出
git log --pretty=oneline --graph //简短的提交历史日志 (可以看到分支的提交结构)
git log --pretty=oneline
- If you want to perform version rollback, you need to know which version you are currently in. Git records the current version through the HEAD pointer.
git reset--hard HEAD ^
^ Previous versiongit reset--hard HEAD~1000
~Several versions in numbersgit reset--hard 595674bdc04935452e583b360e714238b1295bf7
Specify version
3.5 git ignore files
.gitignore
files, lists the patterns of files to be ignored
;
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
src/views/User/components/ConsultItem.vue
3.6 Remote server
- View remote warehouse
git remote
git remote –v
-v是—verbose的缩写(冗长的)
- Add remote address: Let the local warehouse and the remote server warehouse establish a connection
git remote add <shortname> <url>
git remote add origin http://152.136.185.210:7888/gitremotedemo.git
重命名远程地址: git remote rename master newMaster
移除远程地址: git remote remove gitlab
- Specific steps
// 重要 添加远程地址(让本地的仓库和远程服务器仓库建立连接):
// git remote add < shortname > <url>
0. git init // 初始化
1. git remote add origin https://gitee.com/zd1231230/in.git // 关联远程仓库
2.0 git push --set-upstream origin newFetch 提交到远程仓库
2.1 git pull https://gitee.com/zd1231230/in.git master 拉取仓库到主分支
3. 新建仓库 newFetch
4. git commit -a -m "初始化"
5. push
注意点
After associating with the remote warehouse, pull the branch and merge itgit pull
git pull 等于 git fetch + git merge(rebase)
3.7 Branch creation, switching and merging
- Branch creation
git branch 分支名
- Create a branch and merge
git checkout -b <newbranchname>
- Branch merge
git merge <name>
- View and delete branches
git branch
# View all current branchesgit branch –v
# Also view the last commitgit branch --merged
# View all branches merged into the current branchgit branch --no-merged
# View all branches that have not been merged into the current branchgit branch –d hotfix
# Delete the current branchgit branch –D hotfix
# Forced deletion of a branch
3.8 Tracking branches
- Problem 1: The current branch does not have a track branch
- Reason: The current branch is not tracked with the remote origin/master branch
- Without tracking, we execute directly
pull操作的时候必须指定从哪一个远程仓库中的哪一个分支中获取内容
;
- Without tracking, we execute directly
- Direct execution
git push origin master
- If we want to execute git fetch directly, there is a prerequisite: a tracking branch must be set for the current branch.
4. Git workflow (git flow)
- Due to the convenience of using branches on Git, many Git workflows have been generated:
- In other words, you can have multiple open branches at the same time at different stages of the entire project development cycle;
- You can periodically merge certain topic branches into other branches;
- For example, the following workflow:
master
as the main branch;develop
As a development branch, and when there is a stable version, it will be merged into the master branch;topic
Developed as a branch of a certain theme, function or feature, and merged into the develop branch after development is completed;
git fetch 项目地址 分支名称:别名
git fetch https://gitee.com/zd1231230/doctor-demo.git dev:dev
Git flow workflow diagram
article reference: rebase and tag tags