Common git commands and usage specifications

First talk about the commonly used git commands

Clone project

git clone ...

Pull a new branch from the master branch

git checkout -b xxx(分支名字)    根据master分支拉取一个xxx分支出来

git push -u origin xxx(你从master上拉取的分支名字)  将xxx分支推到远程上,因为远程上没有这个新的xxx分支,所以要加-u。第一次将新分支提交到远程上时需要加-u

Submit content to the current development branch

git add .
git commit -m ''
git push

Merge to master branch

git checkout master 切换到master分支

git pull origin master 先拉一下master分支上的代码

git merge xxx 将xxx合并到master分支

git push 将master分支代码推到远程

How to switch branches in git

git checkout xxx(需要切换的分支名)

How to delete a local branch in git

git branch -D xxx(需要删除的分支名)

How to delete a remote branch in git

git push origin --delete xxx(需要删除的分支名)
git push origin :xxx(需要删除的分支名)

How git pulls remote branches

git fetch origin xxx(需要拉取的分支名)

How to merge remote branches in git

git merge  xxx(需要合并的分支名)

How does git cancel the last commit operation:

第一种情况,如果还没有push,只是在本地commit:git reset --hard <commit_id>

第二种情况,如果已经push:git revert <commit_id>

Force the remote code to overwrite the local:

git fetch --all 

git reset --hard origin/master 

git pull

Let me talk about the git specification

The first is the commit specification

1. feat: 新功能
2. fix/to: 修复bug
• fix:产生diff并自动修复此问题。适合于一次提交直接修复问题
• to:只产生diff不自动修复此问题。适合于多次提交。最终修复问题提交时使用fix
3. docs:文档(documentation
4. style:格式(不影响代码运行的变动)。
5 .refactor:重构(即不是新增功能,也不是修改bug的代码变动)。
6. perf:优化相关,比如提升性能、体验。
7. test:增加测试。
8. chore:构建过程或辅助工具的变动。 
9. revert:回滚到上一个版本。
10.merge:代码合并。
11.sync:同步主线或分支的Bug。

For example to add new features:

feat:添加了某个新功能

Then there is the naming convention of our project branch

Master->>Develop:创建开发分支
		loop Sprint 开发阶段
			Develop->>+Feature:创建功能特性分支
			Feature-->>-Develop:完成功能开发
		end
		Develop->>Release:创建预发布分支
		loop Sprint 测试阶段
			Release->>+Fix:创建问题修复分支
			Fix-->>-Release:完成问题修复
		end
		Note right of Release: 发布新版本,打上版本 tag
		Release-->>Develop:回归版本到最新的开发分支
		Release-->>Master:回归版本到最新的主分支
		
		Master->>+Hotfix:创建生产环境问题分支
		Hotfix-->>-Master:完成生产环境问题修复

For example, for a new project, we first create a development branch develop on the master branch, and then we create a branch on the develop branch. Assuming we finish a function, the branch name can be called

feature-dmxy/xxxxxxx-xxx

Feature is the type of branch. This is a functional branch.
dmxy is the abbreviation of our project.
xxxxxxx-xxx. Generally, each feature will have a number. This depends on each company.

Guess you like

Origin blog.csdn.net/weixin_45389051/article/details/115273917