Git Tutorial
Git Tutorial
Git Commit 规范
commit message格式,结尾不加句号或其他标点符号:
<type>(<scope>): <subject>
type(必须),用于说明git commit的类别,只允许使用下面的标识:
feat:新功能(feature)
fix/to:修复bug,可以是QA发现的BUG,也可以是研发自己发现的BUG
fix:产生diff并自动修复此问题。适合于一次提交直接修复问题
to:只产生diff不自动修复此问题。适合于多次提交。最终修复问题提交时使用fix
docs:文档(documentation)
style:格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
perf:优化相关,比如提升性能、体验
test:增加测试
chore:构建过程或辅助工具的变动
revert:回滚到上一个版本
merge:代码合并
sync:同步主线或分支的Bug
scope(可选),用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。
subject(必须),简短描述本次commit的目的,一般不超过50个字,建议使用中文。
例如,根据以上规范的 git commit message 将是如下的格式:
fix(DAO):用户查询缺少username属性
feat(Controller):用户查询接口开发
参考文献:
- 阿里开发者. 如何规范你的Git commit?. 知乎. https://zhuanlan.zhihu.com/p/182553920
Git Summary
1. 设置姓名和email
git config --global user.name "YuboFeng"
git config --global user.email "networkprogramming@yeah.net"
2. 提高命令可读性
git config --global color.ui auto
3. 设置 SSH Key
ssh-keygen -t rsa -C "networkprogramming@yeah.net"
有三处需要用户输入的地方,都按回车即可。
然后,把 .ssh/id_rsa.pub 文件中的内容全部粘贴到 GitHub 上的 Add SSH Key 即可。
cat .ssh/id_rsa.pub
4. 查看本地仓库状态
git status
5. 添加至本地仓库
git add new_file
6. 查看提交日志
git log
-p 选项显示文件修改前后的差别
7. 提交修改至本地仓库
from 暂存区 to 本地仓库
git commit -m "comments"
8. 更新 GitHub 上的仓库
from 本地仓库 to 远程仓库
git push
9. 获取最新的远程仓库分支
git pull origin [brunch-name]
10. 查看更改
提交(commit)之前必须做
git diff HEAD
11. 添加一个远程仓库
git remote add [name] [url]
12. 记住账号密码
git config --global credential.helper store
13. 克隆远程仓库时指定本地文件夹名称
git clone http://github.com/YuboFeng/code.git mycode
Pull Request
Explaning the processing of Pull Request with RaRe-Technologies/gensim.
step 1. Frok
Frok from the origin
step 2. clone
Clone from your Fork
step 3. 创建 branch
首先,我们需要确认分支
$ git branch -a
* develop # develop 为当前分支
remotes/origin/HEAD -> origin/develop
然后,创建特性分支。我们创建一个名为 wordsim240-296-297 的分支。
$ git checkout -b wordsim240-296-297 develop
Switched to a new branch 'wordsim240-296-297' # 当前分支自动被切换
$git branch -a # 再次确认当前分支
develop
* wordsim240-296-297
remotes/origin/HEAD -> origin/develop
对代码仓库进行修改,将修改添加至本地仓库,提交修改:
$ git add .....
$ git commit -m "some editing"
然后,创建远程分支:
$ git push origin wordsim240-296-297
remotes/origin/HEAD -> origin/develop
再次确认分支
$ git branch -a
develop
* wordsim240-296-297 # 分支已被创建
remotes/origin/HEAD -> origin/develop
step 4. 发送 Pull Request
智慧在街市上呼喊,在宽阔处发声。