git
Git Bash
Windows 安装 Git 之后,同时会安装好 Shell 脚本工具,Git Bash
界面可以直接执行 Shell 脚本。
git commit 规范指南
用于说明 commit 的类别,只允许使用下面 7 个标识。
feat:新功能
fix:修补 bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改 bug 的代码变动)
perf:优化相关,比如提升性能、体验
test:增加测试
merge:代码合并
chore:构建过程或辅助工具的变动
分支
git branch: 查看分支
git checkout: 切换分支
git checkout -b <name>
: 创建并切换到新分支git branch -d <name>
: 删除本地分支git merge: 将指定分支合并到当前分支
Tag 发版
每一次发布线上版本,都需要添加一个tag
- 添加 tag:
git tag -a <tagname> -m "added description release notes"
git tag -a v1.0-beta -m "v1.0 beta版本发布上线"
查看 tag:
git tag
删除 tag:
git tag -d <tagname>
推送 tag:
git push origin <tagname>
回滚
- 第一步:进行本地回滚
git reset --hard commit节点
- 第二步:推送至远程
git push -f
暂存
- git stash: 将修改暂存,再去新建分支,然后在新分支上恢复
- git stash pop: 将暂存的修改恢复
创建一个新的存储库
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/licong96/case3-old-island.git
git push -u origin main
2
3
4
5
6
推送现有的存储库
git remote add origin https://github.com/licong96/case3-old-island.git
git branch -M main
git push -u origin main
2
3
每次都需要输入用户名和密码的解决方法
执行:
git config --global credential.helper store
会在本地生成一个文本,上边记录账号和密码
然后你使用上述的命令配置好之后,再操作一次 git pull,然后它会提示你输入账号密码,这一次之后就不需要再次输入密码了。
git 操作规范
- 拉新分支
feature-xxx
、fix-xxx
、hotfix-xxx
- 修改代码
- commit 规范
- 往 dev 分支提交 pr Pull Request
- 代码走查
- 合并代码到 dev
- 等待发布上线
分支管理
从公司代码仓库中 fork 一份到自己的仓库里,自己所有的开发都在自己的仓库里,就不会影响到公司仓库。
从你的仓库中
git clone
到你本地做开发。从 master 分支中新建一个 dev 分支,比如
dev/0.0.1
,开发完成之后,做一系列 git 操作,准备上线,合并到 master。从你的仓库
pull request
到公司代码仓库,代码检测通过之后合并,创建 tags 为release/0.0.1
并且删除开发分支,发布上线。
传统方式:
Github flow
简化方式,最大的优点就是简单
参考文档:https://www.cnblogs.com/javaxubo/p/16652845.html#_label5open in new window