git
Distributed version control
work process
- Workspace (write terminal code)
- Buffer
- Repository
- The content repository moved to the distal (GitHub / gitee)
- Work for writing code
- After completion of the work area code editing code submitted to the staging area
- Staging area: a filter layer similar to the protection zone and the code repository to avoid wrong operation
- Code in the temporary area is formed into the repository (version can be processed)
Download git
git bash terminal operation
git --version 查看版本
git first operational configuration of personal information
git config --global user.name 名字
git config --global user.email 邮箱地址
git config --list
Initialize git
一项目被git管理 先初始化
git init
git默认情况下不会管理空文件
git 管理文件包括所有的子文件
View the current status of the project file management git
git status
- 如果文件显示红色,,文件在工作区没有向暂存区提交
- 如果文件显示绿色,文件在暂存区没有向版本库提交
The submission of the work area to the staging area
git add index.html 提交index.html文件
git add css/ 提交css文件夹
git add --all 提交所有文件
git add . 提交所有
Pull back to the staging area file workspace
git reset HEAD -- index.html 拉回文件
git reset HEAD -- css/ 拉回文件夹
git reset HEAD -- . 拉回所有
Will be submitted to the staging area to the repository (the formation of a version control)
git commit -m '版本日志';
View version
git log
返回:id
提交作者
时间
git reflog
返回 :版本号 版本日志
Version rollback
git reset --hard 版本id
git reset --hard HEAD ^ 一个^ 代表回退一个版本
Than to file
git diff 文件名称 查看当前文件工作区好人暂存区的不同
git diff 分支名 查看工作区和版本库的不同
git diff --cached 查看缓存区和版本库的不同
Delete files
git rm -f 文件名 删除暂存区和工作区的文件
git rm --cached 删除暂存区 保留工作区
Empty file management git / git to ignore certain file
- Empty folder inside the folder management in place a .gitkeep;
- Not to manage a file git: Place a file in the following directory git management: gitignore do not need to add files to the management of the .gitignore
Branch
master the main branch
- master project can not be developed
- 1. Keep final cleanest code
- 2. The existence of public libraries
- 3. The entire project of great architecture
- Create a development branch (branch create yourself)
- dev branch
- Merge each branch of the overall project (for testing for the project Union)
- The development process, need to be merged into the project code
- dev branch
Branch operations
git branch 查看分支
git branch 分支的名称 创建分支
git checkout 分支名称 切换分支
git checkout -b 分支名校 创建并切换分支
git branch -d 分支名称 删除分支
git merge 分支名称 合并
The distal end (github / gitee)
想把本地仓库 推送到远端
1. 在github创建仓库
2. 拿到远端仓库地址
a.通过https
b.通过SSH秘钥
3.将本地仓库按照远端仓库地址推送
According to the local repository push the distal warehouse address
git remote add origin 添加远端仓库的地址
git push -u origin 分支名称
git remote rm origin 如果更改远端仓库地址之前 先把上一次远端连接移除
The distal end of the pull local warehouse
git clone 远端地址
git clone -b 远端分支名称 远端仓库地址
git pull origin 分支名称
Configuration key
ssh-keygen -t rsa -C "你的邮箱地址"
cat ~/.ssh/id_rsa.pub
配置密钥流程:
1:在终端 ssh-keygen -t rsa -C “你的邮箱地址”
2:在终端 cat ~/.ssh/id_rsa.pub
3:得到 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFI/4Xh6vEnBKoadpohBvCP8PQdi0zGRupOfn8IrWqz+G9ZAGFJdAEDItXhQs6HIfk3ps34xnPuiSRAE8y/oCtNiUgcQ0Q8l2TGhFBZ2q1rrv15+HmBhf07obsDGNU01WxbVwf81Vv8R6Q9LI7D31j8ifFHJJOKtBEJoMMDuehHnXltzQ5/onRpE+QRBW3UuX9Fhvw/aLoX9gD5M3AuwRzSqe/gALViKtzr+Pj2tRjbwUQwmHR62Obz9kFTHQ414GmtUYpRSRg6VwAJ5dl+heijW1j6bR1gWpnyKW5Hs6PM9PAIx9UiYHfpAl+kPYguWxZHigSd7OoMzAhBU64dyb9ZFSIZqfhodQgiEIZVj3CKTYAgdLSWchTVLq6U3te+rhAnrWD2MBT7IFPZ+jQZoH1kNhx3y8OvEq6TudrP6ICkvDN6dYD4r007gaXmRT5WFqWaKGhf2XI8fJg/cAnWMImURcfUI/KgIl1LXCMUP/lT1/HbTjkTa7E0n7tIqlXJAM= [email protected]
4:把拿到的密钥配置到github
git conflict
Be sure to pull the remote repository of code, and then modify, or create a conflict, error.
solution:
Manually merge
vscode visualization tools
ctrl shift g: Source Control
+ 暂存
√ 提交
Little Turtle visualization tools
TortoiseGit