1 安装git
平台 | 下载方法 |
---|---|
Windows | https://git-scm.com/downloads |
Centos / RedHat | yum –y install git |
Ubuntu/Debian | apt-get install git |
安装完成后,可以右击打开git bash
2 配置ssh key
获取SSH公钥
ssh-keygen -t rsa
平台 | 文件 |
---|---|
Windows | C:\Users\Gavin\.ssh\id_rsa.pub |
Linux | ~/.ssh/id_rsa.pub |
注意:Windows路径Gavin对应你自己的用户
将id_rsa.pub中的内容复制到下面配置页面中的ssh public keys中
3 配置git信息
git config --global user.name gavin
git config --global user.email gavin@csdn.com
git config --global gitreview.username gavin
git config --global core.editor vim
(下面我未配置,暂时还未发现问题)
git config --global gitreview.scheme https
git config --global gitreview.port 443
查看git配置信息
cat ~/.gitconfig
回显以下信息:
[user]
name = gavin
email = gavin@csdn.com
[gitreview]
username = gavin
[core]
editor = vim
[filesystem "Oracle Corporation|1.8.0_131|-1270943953"]
timestampResolution = 1001 microseconds
minRacyThreshold = 0 nanoseconds
[filesystem "Oracle Corporation|1.8.0_131|1713440874"]
timestampResolution = 1001 microseconds
minRacyThreshold = 0 nanoseconds
[commit]
template = C:/Users/Gavin/.gitcommit
4 配置git提交模板
平台 | 文件 |
---|---|
Windows | C:\Users\Gavin\.gitcommit |
Linux | ~/.gitcommit |
vi .gitcommit
键入下面模板内容:
[本次提交概要信息]
执行命令,使模板生效:
git config --global commit.template ~/.gitcommit
5 拉取代码
进入gerrit 点击Project----List选择需要拉取的项目,复制SSH链接到git bash
进入下载的路径下,可以切换分支
git checkout develop
回显下面信息
Switched to a new branch 'develop'
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
6 提交代码
修改代码后
- 查看状态
git status
回显以下信息,可以看见修改的文件
On branch develop
Your branch is up to date with 'origin/develop'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.text
nothing added to commit but untracked files present (use "git add" to track)
- 将修改的代码add到仓库
git add .
- 检查与远端仓库是否可连接
git review -s
回显下面信息
Creating a git remote called 'gerrit' that maps to:
ssh://xxxxxxxxxx.git
git remote -vv
回显
gerrit ssh://xxxxxxxx.git (fetch)
gerrit ssh://xxxxxxxx.git (push)
origin ssh://xxxxxxxx (fetch)
origin ssh://xxxxxxxx (push)
- 生成一次commit历史
git commit
编辑commit信息
[brief description]
Code Source From: [4选1]
# Self Code / OpenSource / 3rd party Code / Other
Description: []
Jira: #[可选]
市场项目编号(名称): []
- 提交到develop分支
git review develop
remote:
remote: Processing changes: refs: 1, new: 1
remote: Processing changes: refs: 1, new: 1
remote: Processing changes: refs: 1, new: 1, done
remote:
remote: SUCCESS
remote:
remote: New Changes:
remote: http://xxxxxx/+/2647505 Add AI chip
To ssh://xxxxxx.git
* [new branch] HEAD -> refs/for/develop
- 代码退回,修改后重新提交
git commit --amend
重新提交
git review develop
7 git其他操作
7.1 提交日志查看
git log
7.2 切换本地分支
git checkout master
持续更新……