1、配置环境变量

  • 配置git全局用户名

git config --global user.name "qujunorz"
git config --global user.email "qujunorz@gmail.com"#gerrit中注册的用户名与邮箱
  • 修改.git/config

[remote "gerrit"]url = ssh://qujunorz@$代码url地址fetch = +refs/heads/*:refs/remotes/gerrit/*
  • 创建.git/hooks中的commit-msg文件
    #为了避免错误“remote: ERROR: missing Change-Id in commit message footer”

#!/bin/sh
# From Gerrit Code Review 2.7
#
# Part of Gerrit Code Review (
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# ## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#unset GREP_OPTIONSCHANGE_ID_AFTER="Bug|Issue"MSG="$1"
# Check for, and add if missing, a unique Change-Id
#
add_ChangeId() {clean_message=`sed -e '/^diff --git a\/.*/{s///q}/^Signed-off-by:/d/^#/d' "$MSG" | git stripspace`    if test -z "$clean_message"thenreturnfi# Does Change-Id: already exist? if so, exit (no change).if grep -i '^Change-Id:' "$MSG" >/dev/null    thenreturnfiid=`_gen_ChangeId`T="$MSG.tmp.$$"AWK=awk    if [ -x /usr/xpg4/bin/awk ]; then# Solaris AWK is just too brokenAWK=/usr/xpg4/bin/awk   fi# How this works:# - parse the commit message as (textLine+ blankLine*)*# - assume textLine+ to be a footer until proven otherwise# - exception: the first block is not footer (as it is the title)# - read textLine+ into a variable# - then count blankLines# - once the next textLine appears, print textLine+ blankLine* as these#   aren't footer# - in END, the last textLine+ block is available for footer parsing$AWK 'BEGIN {# while we start with the assumption that textLine+# is a footer, the first block is not.isFooter = 0footerComment = 0blankLines = 0}# Skip lines starting with "#" without any spaces before it./^#/ { next }# Skip the line starting with the diff command and everything after it,# up to the end of the file, assuming it is only patch data.# If more than one line before the diff was empty, strip all but one./^diff --git a/ {blankLines = 0while (getline) { }next}# Count blank lines outside footer comments/^$/ && (footerComment == 0) {blankLines++next}# Catch footer comment/^\[[a-zA-Z0-9-]+:/ && (isFooter == 1) {footerComment = 1}/]$/ && (footerComment == 1) {footerComment = 2}# We have a non-blank line after blank lines. Handle this.(blankLines > 0) {print linesfor (i = 0; i < blankLines; i++) {print ""}lines = ""blankLines = 0isFooter = 1footerComment = 0}# Detect that the current block is not the footer(footerComment == 0) && (!/^\[?[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\//) {isFooter = 0}{# We need this information about the current last comment lineif (footerComment == 2) {footerComment = 0}if (lines != "") {lines = lines "\n";}lines = lines $0}# Footer handling:# If the last block is considered a footer, splice in the Change-Id at the# right place.# Look for the right place to inject Change-Id by considering# CHANGE_ID_AFTER. Keys listed in it (case insensitive) come first,# then Change-Id, then everything else (eg. Signed-off-by:).## Otherwise just print the last block, a new line and the Change-Id as a# block of its own.END {unprinted = 1if (isFooter == 0) {print lines "\n"lines = ""}changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"numlines = split(lines, footer, "\n")for (line = 1; line <= numlines; line++) {if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {unprinted = 0print "Change-Id: I'"$id"'"}print footer[line]}if (unprinted) {print "Change-Id: I'"$id"'"}}' "$MSG" > "$T" && mv "$T" "$MSG" || rm -f "$T"}_gen_ChangeIdInput() {    echo "tree `git write-tree`"if parent=`git rev-parse "HEAD^0" 2>/dev/null`    thenecho "parent $parent"fiecho "author `git var GIT_AUTHOR_IDENT`"echo "committer `git var GIT_COMMITTER_IDENT`"echoprintf '%s' "$clean_message"}_gen_ChangeId() {_gen_ChangeIdInput |git hash-object -t commit --stdin
}add_ChangeId
  • 修改ssh_config

KexAlgorithms +diffie-hellman-group1-sha1
  • 上传ssh公钥至服务器

2、代码上传操作

  • 克隆代码到本地

git clone $代码在gerrit中地址
  • 新建一个分支

git branch -a
#列出本地或远程的所有分支
git branch -r
#列出远程分支
git branch [branch_name]
## 新建分支
  • 切换到分支

git checkout  [branch_name]
或者不使用git branch新建,直接git checkout -b实现新建与切换
git checkout -b [branch_name]
  • 修改文件并提交

touch aecho “revise” >a
git add a
#添加新文件,如果只是修改或者删除则不需要
git addgit commit -a
#将修改内容提交到仓库中
git commit --amend
#对于已经提交过的代码,如果需要修改,可以借助 git commit --amend 来进行。
  • 查看状态并向master提×××并请求

git status
#查看是否已经
commitgit  log
#查看提交日志
git-review master

3、报错

sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.
  • 使用ssh-add命令添加私钥
    参考:https://help.github.com/articles/error-permission-denied-publickey/

转载于:https://blog.51cto.com/qujunorz/1901538

gerrit的git配置流程相关推荐

  1. windows的git配置流程

    一.安装.配置git数据 1.下载git软件--   Git - Downloads 2.软件安装 软件下载好之后,双击一路next安装即可(中间不需要自定义,默认就可以):安装好之后,打开git B ...

  2. Gitlab+Gerrit+Ldap+nginx+mysql 之Gerrit搭建与配置(一)

    公司之前一直用gitlab来存放项目代码 ,目前因为业务需要(代码bug太多)需要引入gerrit来进行code review. 最初用的是centos 7.4,但是安装完成后,GerritResou ...

  3. Gitorious基本配置流程

    一. GitHub.Gitorious对比: Gitorious与GitHub二者主要功能一样,都是git的版本管理仓库. 区别: 1. Gitorious比GitHub更早诞生: 2. Gitori ...

  4. 【java学习之路】(java框架)002.Git配置及使用

    目标 了解Git基本概念 能够概述git工作流程 能够使用Git常用命令 熟悉Git代码托管服务 能够使用idea操作git 概述 开发中的实际场景 场景一:备份 小明负责的模块就要完成了,就在即将R ...

  5. Git使用流程及技巧 - 详细教程

    Git使用流程及技巧 - 详细教程 前言 1. 技巧 1.1. 基础技巧 1.2. 提升SSH传输速度 1.3. 解决Git Bash命令行的中文乱码问题 1.3.1. 情况1:内部资源乱码 1.3. ...

  6. Git配置、版本控制与分支管理

    文章目录 一.创建版本库 1. 配置git环境 二.时光机穿梭 1. 版本回退 2. 撤销修改 3. 删除文件 三.分支管理 1. 创建与合并分支 2. 解决冲突 3. Bug分支 4. 多人协作 参 ...

  7. git 配置ssh 秘钥

    git支持http和ssh两种Clone方式: PS:Clone即下载源码 如何配置git的ssh key,以便我们可以通过git方式下载源码. 需要经过以下几个步骤 1.配置账户和邮箱: 通过以下命 ...

  8. git 进阶系列教程-------git使用流程

    GIT使用流程 前言 初衷 git是一门很容易入门的项目管理工具,但是它是一门很难精通的技术. git pull/git add ./git commit -m "message" ...

  9. git配置及常见命令

    首先我们需要本地Git与远程GitHub连接的建立,只有将Git本地与远程的GitHub建立了连接以后我们本地的项目才能上传至远程服务器 ** 配置流程: ** 1.在git中配置全局的github账 ...

最新文章

  1. 异地多活场景下的数据同步之道 | 珍藏版
  2. μC-/OS II(一) PC编译环境的搭建
  3. html优美界面左侧下拉,一组时尚的侧边栏菜单和下拉列表UI设计
  4. 使用Http协议访问网络--HttpClient
  5. PyQt5学习笔记03----Qt Designer生成源码
  6. 从另一页面调用html代码_GNE v0.1正式发布:4行代码开发新闻网站通用爬虫
  7. W3C 宣布:WebAuthn 成为正式 Web 标准
  8. CentOS 6.5 Nginx 配置
  9. Vue学习笔记(五)
  10. android组件化掘金,MVPArms 官方快速组件化方案
  11. 使用React Native源码编译Android项目
  12. android 菜鸟面单打印_android菜鸟 实战项目之简单界面实现
  13. 数模论文写作方法3|问题重述
  14. OSR推出在线SSL/TLS安全测试工具
  15. delphi BMP与jpg互转
  16. ZTD 简单做十个好习惯总结
  17. 追风筝的人 第三章
  18. Mysql innodb 间隙锁
  19. Ubuntu 安装企业微信
  20. 2021最新chrome浏览器与chromedriver版本对照表

热门文章

  1. Mac配置Java环境变量等
  2. SARscape_5.2.0和SARscape_5.2.1安装包下载
  3. 转载:【OpenCV入门教程之四】 ROI区域图像叠加初级图像混合 全剖析
  4. 线性代数学习资料汇编
  5. 计算机视觉与深度学习 | 机器学习中的数学——入门机器学习
  6. 模糊搜索时搜索结果中关键词变为不同颜色
  7. 数据结构一:链表(linux链表)
  8. 安装texlive并用latex编写一段中文,最后生成pdf文件
  9. android 全局进度条,Android:如何在中心显示全屏进度条
  10. linux snmp进程,linux snmpwalk命令详解