git提交代码

1 安装git

平台下载方法
Windowshttps://git-scm.com/downloads
Centos / RedHatyum –y install git
Ubuntu/Debianapt-get install git

安装完成后,可以右击打开git bash

在这里插入图片描述在这里插入图片描述

2 配置ssh key

获取SSH公钥

ssh-keygen -t rsa
平台文件
WindowsC:\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提交模板

平台文件
WindowsC:\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

持续更新……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值