# 初始化
git init
# 查看远程仓库
git reomte -v
# 关联远程仓库
git remote add origin <urlName>
# 切换分支
git checkout <branchName>
# 创建并切换到新分支
git checkout -b <branchName>
# 删除分支
git branch -d <branchName>
# 查看本地分支
git branch
# 查看远程分支
git branch -r
# 查看全部分支
git branch -a
# 拉取远程分支
git fetch origin
# 从远程分支创建本地分支(会删除原有内容)
git checkout -b <localeBranch> origin/<remoteBranch>
# 查看本地分支与远程分支的关联
git branch -vv
# 拉取远程分支代码
git pull
# 推送到远程分支
git push -u origin <remoteBranch>
# 查看日志
git log
# 或
git log --oneline --decorate --graph --all
# 回滚版本
git reset --hard <version No>
# 强制推回
git push -f
# 删除远程分支
git push origin -d <remoteBranch>
# 查看标签
git tag
# 查看特定标签
git tag -l 'v1.8' (包含'v1.8')
# 创建标签
git tag -a <tagName> -m <comment>
# 或
git tag <tagName>
# 标签与对应的提交信息
git show <tagName>
# 后期补标签
git log
git tag -a <tagName> <commitNo>
# 删除标签
git tag -d <tagName>
# (删除)更新远程标签
git push origin :refs/tags/<tagName>
# 本地标签推送到远程分支
git push origin master --tags
回滚流程
// 回滚master分支
1. 远程master创建远程hotfix分支
2. 本地拉取远程仓库hotfix分支内容
3. git log 查看版本,回滚本地hotfix到某一版本
4. git push 推入远程hotfix分支
5. merge 远程hotfix分支到远程master分支
Commit 提交规范
# commit message 格式
<type>: <subject> # 冒号后有空格
# type
feat: 新功能(feature)
fix: 新功能
docs: 文档(documentation)
style: 格式(不影响代码运行的变动)
refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
test: 增加测试
chore: 构建过程或辅助工具的变动
# 例如
git commit -m 'fix: 修复页面BUG'