目 录
修改记录
版本号 | 修改章节 | 修改内容简述 | 修改人 | 修订日期 |
V1.0 | 无 | |||
注1:每次更改归档文件时,需填写此表。 注2:文件第一次归档时,“修改内容简述”栏写“无”,其它栏空。 |
Git提交规范
1. 目的
1)规范代码提交
2)方便TD变更统计
3)有利于问题回溯以及快速定位
2. 基本原则
2.1 git个人信息设置
1)用户名设置:git config --global user.name <name>
示例:git config --global user.name kengong
2)用户邮箱设置:git config --global user.email <email>
示例:git config --global user.email ken.gong@innos.com
2.2 linux时间设置
如果检查日期、时间不对的话,根据下面方法设置正确值。
1)检查日期、时间是否正确,linux控制台命令如下,
date
2013年 07月 19日 星期五 15:17:00 CST
2)修改日期、时间,命令如下,
sudo date -s <当前日期>
示例:sudo date -s “2013年 07月 19日 星期五 15:17:00 CST”
2.3 git提交要求
一次提交(commit)只能是一个变更或功能,不允许一次提交多个变更和功能,便于版本回溯及检查。
像下面的提交是必须禁止的,
1)不允许一次提交多个变更,
git commit –m “resolve PR00001 and PR00002”
2)不允许一次提交多个功能,
git commit –m “add LCD and TP driver”
2.4 git提交格式
提交模板如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model-Custom :
# Select the commit type, Delete the # symbol
#TD NO :
#BUG :
#Feature :
# Set the Reason and Reviewers
Reasons :
Reviewers :
#----------------------------------------------------------------
其中,
Model-Custom表示机型和定制客户,比如D10A-Smartfren。如果解决的是平台或者基线相关的问题,此处填写PB。
TD NO表示此次提交解决的是TD上面的问题,此处填写TD号以及问题描述。
BUG表示此次提交解决的是一个BUG,主要就是除测试部反馈的问题之外的BUG,此处填写问题描述。
Feature表示此次提交为一个功能,此处填写功能描述。
Reasons表示问题原因及解决方法。
Reviewers表示评审者,暂时保留不填。
定制TD问题提交示例如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model- Custom: D10-HighScreen
# Select the commit type, Delete the # symbol
TD NO : TD123456,Resolve acceleration invalid after system startup
#BUG :
#Feature :
# Set the Reason and Reviewers
Reasons : NULL pointer in startup initialize
Reviewers :
#----------------------------------------------------------------
定制BUG问题提交示例如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model- Custom: D10-HighScreen
# Select the commit type, Delete the # symbol
#TD NO :
BUG : system can not resume after suspend
#Feature :
# Set the Reason and Reviewers
Reasons : LCD parameter is not right
Reviewers :
#----------------------------------------------------------------
定制Feature问题提交示例如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model- Custom: D10-HighScreen
# Select the commit type, Delete the # symbol
#TD NO :
#BUG :
Feature : add xxx feature
# Set the Reason and Reviewers
Reasons : add xxx feature
Reviewers :
#----------------------------------------------------------------
平台功能提交示例如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model- Custom: PB
# Select the commit type, Delete the # symbol
#TD NO :
#BUG :
Feature : Add LCD driver
# Set the Reason and Reviewers
Reasons : Add LCD driver
Reviewers :
#----------------------------------------------------------------
机型TD问题提交示例如下,
#----------------------------------------------------------------
# Set the Model and Custom
Model- Custom: D10A
# Select the commit type, Delete the # symbol
TD NO : PR00002, volume is too small
#BUG :
#Feature :
# Set the Reason and Reviewers
Reasons : modify the default volume
Reviewers :
#----------------------------------------------------------------
2.5 git提交检查
代码提交之前和提交之后必须做如下检查,
1)提交修改之前必须验证是否可编译通过、是否已完全解决此问题、是否会引入其他问题。
2)对于紧急任务,提交后必须重新克隆一份代码验证此次提交是否可编译通过、是否已完全解决此问题、是否会引入其他问题。
3)对于非紧急任务,提交之后必须重新克隆一份代码验证此次提交是否可编译通过,并在第二天取冒烟版本验证提交是否已完全解决问题、是否会引入其他问题。
3. git基本操作
1)命令帮助
git xxx –help或者man git xxx
2)设置
设置用户名,
git config --global user.name
设置用户邮箱,
git config --global user.email
设置颜色显示,
git config --global color.ui true
设置提交模板,
git config --global commit.template xxx
3)克隆代码仓库
git clone [--bare] <repository> [<directory>]
比如git clone gitosis@192.168.13.227:8X26_QRD_1101014.git
4)显示状态信息
git status
5)添加提交任务
git add:添加修改文件
git rm:删除文件
git mv:修改文件名或移动文件
6)显示差异
git diff:提交任务与工作区差异
git diff HEAD :当前分支与工作区差异
git diff --cached :暂存区与版本库差异
7)提交修改到本地仓库
git commit:将暂存区任务提交到本地仓库
git commit --amend:修正最后一次提交
8)显示提交日志
git log:只是显示简单的提交记录
git log -p:显示具体的文件修改
9)远程操作
git pull : 获取远程更新并合并到本地仓库
git push : 将当前提交推送到远程仓库
10)分支操作
git branch:显示本地分支
git branch -a:显示本地和远程所有分支
git branch <branch>:创建本地分支
git branch -d <branch>:删除本地分支
git branch -m <branch>:修改本地分支
11)重置
git reset [<commit>] [--] <paths>:用commit节点的文件替换暂存区中的文件
git reset --soft <commit>:改变引用指向到commit节点,不改变暂存区和工作区
git reset --mixed <commit>:改变引用指向到commit节点,并且用commit节点内容替换暂存区,不改变工作区
git reset --hard <commit>:改变引用指向到commit节点,并且用commit节点内容替换暂存区和工作区
12)检出
git checkout <branch>:切换到分支branch
git checkout -b <new_branch> [<start_point>]:从start_point创建新分支,并切换到新分支
git checkout [<commit>] [--] <paths>:用commit节点文件覆盖工作区和暂存区文件
13)反转提交
git revert <commit>:撤销commit节点的提交
14)冲突解决
git merge [--no-commit] <commit>:将commit节点内容合并到当前分支
git mergetool:通过工具来合并
15)里程碑
git tag -m <msg> <tagname> [<commit>]:在commit节点创建一个名为tagname 的tag,说明信息为msg