Git工具
Git 一个分布式版本管理工具,
学习资料: https://www.liaoxuefeng.com/wiki/896043488029600/1317161920364578
其中:
解决冲突、分支管理策略、Bug分支、Feature分支、多人协作、Rebase
暂未学习git switch 需要git 版本 >= 2.23
Git 提交规范
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>
Header部分
type:(必须项)
feat: A new feature(新增feature)
fix: A bug fix(修复bug)
docs: Documentation only changes(仅文档更改,如README.md)
refactor: A code change that neither fixes a bug nor adds a feature(代码重构,没有新增功能或修复bug)
perf: A code change that improves performance(优化相关,如提升性能、用户体验等)
test: Adding missing tests or correcting existing tests(测试用例,包括单元测试、集成测试)
build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)(影响构建系统或外部依赖关系的更改(示例范围:gulp、broccoli、npm))
chore: Other changes that don't modify src or test files(其他不修改src或测试文件的更改)
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)(不影响代码含义的更改(空格、格式、缺少分号等))
ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)(对ci配置文件和脚本的更改)
revert: Reverts a previous commit(还原以前的提交)
scope:(非必须)
本次提交影响范围、功能模块等
subject::(必须)
本次提交的简要标题, 不超过50个字符
Body部分(非必须)
详细描述本次提交
Footer部分(非必须)
- 不兼容变动:以 BREAKING CHANGE 开头
- 关闭Issue:Closes #issue
工具人命令汇总
-
初始化本地仓库:
git init
-
添加文件到本地暂存区:
git add <file>
-
将暂存区中的文件提交到本地仓库:
git commit -m <message>
-
查看本地仓库状态(文件是否被修改):
git status
-
查看变动信息(查看文件修改内容):
git diff
-
查看本地仓库历史记录(oneline 简要输出, 可以查版本ID):
git log <--pretty=oneline>
-
本地仓库回退:
git reset --hard <HEAD^ | commit ID>
-
记录每一次操作命令(可以查版本ID):
git reflog
-
撤销暂存区(add 之后)的修改:
git reset HEAD <file>
-
丢弃工作区(未add 之前)的修改:
git checkout -- <file>
-
设置远程仓库:
git remote add origin https://gitee.com/zy7y/learngit.git
-
推送到远程仓库(并将本地master与远程master关联):
git push -u origin master | git push origin master
-
从远程仓库拉取:
git pull <仓库地址>
-
查看远程仓库信息:
git remote -v
-
删除(解绑关系)远程仓库:
git remote rm <name>
-
从远程库克隆(默认是克隆默认分支):
git clone https://gitee.com/zy7y/apiAutoTest.git
-
克隆指定分支:
git clone -b dev https://gitee.com/zy7y/apiAutoTest.git
-
查看本地仓库分支:
git branch
-
切换分支:
git checkout <分支名>
orgit switch <分支名>
-
创建并切换分支:
git cehckout -b <分支名>
orgit switch -c <分支名>
-
删除分支:
git branch -d <分支名>
-
合并指定分支到当前分支(dev -> master ):
git merge <分支名>
1. dev 分支工作后 add 到暂存区 2. commit 提交 到仓库 3. 切换到 master 分支 4. git merge dev # 将 merge 后面的分支 合并到当前分支 5. 合并完成后删除 dev 分支 #
-
查看所有标签:
git tag
-
创建标签:
git tag <标签名>
-
指定的版本ID打标签:
git tag <标签名> <commitID>
-
查看标签信息:
git show <标签名>
-
删除标签:
git tag -d <标签名>
-
推送标签到远程:
git push origin 标签名
-
删除远程仓库标签:
git push origin :refs/tags/<tagname>