2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Git is an open source distributed version control system that can effectively and quickly handle version management of projects ranging from very small to very large.
Git is distributed. Git does not need a central server. What we have on each computer is the same. We use Git and have a central server just to facilitate the exchange of everyone's modifications, but the status of this server is the same as that of each of our PCs. We can treat this server as a developer's PC, just for everyone to easily exchange code without shutting down. Without this server, everyone can still work, but it is inconvenient to "exchange" modifications.
Centralized version control tools
Centralized version control tools, the version library is stored in a central server. Everyone in the team downloads the code from the central server when working. It must be connected to the Internet to work, either a local area network or the Internet. After personal modification, submit it to the central version library. Such as: SVN, CVS
Distributed version control tools
Distributed version control systems do not have a "central server". Everyone's computer is a complete version library. In this way, when working, there is no need to connect to the Internet, because the version library is on your own computer. When multiple people collaborate, they only need to push their own changes to each other, and they can see each other's changes. For example: Git
Git Workflow:
clone: Clone code from the remote repository to the local repository
checkout: Check out a repository branch from the local repository and modify it
add: Submit the code to the staging area before submitting
commit: Submit to the local warehouse, where the modified historical versions are saved
fetch: Fetch from the remote repository to the local repository without performing any merging actions
pull: Pull from the remote library to the local library and automatically merge (merge), and then put it in the workspace, which is equivalent tofetch merge
push: Push code to the remote repository
git config
: Configuration information
# 设置用户信息
git config --global user.name "userName"
git config --global user.email "Email"
# 查看配置信息
git config --global user.name
git config --global user.email
alias
: Configure command aliases, in~/.bashrc
Add configuration in and execute after modification.source ~/.bashrc
# 部分windows系统不允许用户创建.开头的文件,可以在gitBash中执行
touch ~/.bashrc
# 在~/.bashrc中添加内容,输出git提交日志
alias git-log='git log --pretty=oneline --all --graph --abbrev-commit'
git init
: Initialize the current directory as a git repository. After successful execution, multiple.git
folder
git status
: View modification status (Temporary storage area, work area)
git add
: Add changes to one or more files in the workspace to the staging area
git add 单个文件名 | 通配符
# 将所有修改加入到暂存区
git add .
git commit
: Submit the contents of the staging area to the current branch of the local warehouse,git commit -m '注释内容'
git log
: View submission log and configure aliasesgit-log
git log [option]
--all 显式所有分支
--pretty=oneline 将提交信息显示为一行
--abbrev-commit 使得输出的commitId更简短
--graph 以图的形式显示
git reset
: Version rollback
# 查看已经删除的记录,可以看到已经删除的提交记录
git reflog
# 版本切换,commitId可以通过git log查看
git reset --hard commitId
git branch
: Check the local branch. Using branches means that you can separate your work from the main line of development to fix bugs and develop new features so as not to affect the main line
master(Production) Branches: online branches, main branches, branches corresponding to small and medium-sized projects as online applications
develop(Development) Branch: It is a branch created from the master branch. It is generally used as the main development branch for the development part. If there is no other parallel development and different phase launch requirements, you can develop in this version. After the stage development is completed, it needs to be merged into the master branch and prepared for launch.
feature/xxx branch: a branch created from develop, usually developed in parallel at the same time, but not launched at the same time, and merged into develop branch after completing the research task on the branch
hotfix/xxx branch: a branch derived from master, generally used for online bug fixes. After the fix is completed, it needs to be merged into the master, test, and develop branches
test(test) Branch
pre(Pre-launch) Branch
# 查看本地分支
git branch
# 创建本地分支
git branch 分支名
# 切换分支
git checkout 分支名
# 切换到一个不存在的分支,创建并切换
git checkout -b 分支名
# 合并分支,一个分支上的提交可以合并到另一个分支
git merge 分支名
# 删除分支,不能删除当前分支,只能删除其它分支
# 删除时需要做各种检查
git branch -d 分支名
# 强制删除,不做任何检查
git branch -D 分支名
Conflict resolution: When there may be conflicts in the modifications to files on two branches, such as modifying the same line of the same file at the same time, you need to manually resolve the conflict. The steps are as follows:
git remote add
: Add a remote repository. This operation is to initialize the local library first, and then connect to the created remote library
git remote add