---
title: "cgywin+git+gerrit设置之二"
author: "snowstone"
date: "2014-05-04T23:56:51Z"
tags: ["Git", "cygwin", "gerrit"]
categories: ["编程语言"]
slug: "cgywin-git-gerrit"
draft: false
lastmod: "2014-05-05T00:10:03Z"
id: 2059885
url: "https://snowstone.iteye.com/blog/2059885"
---

Cygwin64 Terminal按照个人习惯设置好后，下面开始设置git。

**1.设置账号**

进入cygwin的HOME目录，使用下面命令生成你的Public Key

```
ssh-keygen -t rsa -C yourname
```

就会为你生成一个SSH Key，然后会询问一些保存文件的位置，设置密码神马的，直接回车，回车，回车，默认的就可以了。因为主要是在本地使用，可不使用口令，这样会方便一些，不然做什么事情都要密码，各种不爽，所以直接回车就可以了！

这里需要注意的是yourname上不需要加任何引号即可。

![](http://dl2.iteye.com/upload/attachment/0096/7581/0445a831-7099-38e9-bc26-9dd997788dff.jpg)

设置你的Email和Nickname

```
git config --global user.name yourname
git config --global user.email youremail
```

另外，还必须进行一下配置设置编码方式为utf8，否则gerrit上处理中文会是乱码；

```
git config --global core.quotepath false
git config --global i18n.logoutputencoding utf8
git config --global i18n.commitencoding utf8
```

 

设置完成后，可以通过git config --list查看是否生效

 

如果想你设置的账户名在改计算机下的所有用户都生效，则可以输入：

```
git config --system user.name yourname
git config --system user.email youremail
```

 

git输出（比如log、status）彩色显示，使用下面的命令配置：

 

```
git config --global color.ui auto
```

 

**2.激活你的gerrit账户**

 浏览器打开http://xxxx/gerrit

（刚才你登录的这个账号只是apache下的账号，想要使用gerrit，还要按照以下步骤激活你的gerrit账户），点击“Register New Email …”，填入你的email地址，点击“Register”：

![](http://dl2.iteye.com/upload/attachment/0096/7587/90e74d4d-f364-3444-8fac-cfa41b54ac01.jpg)

然后你的邮箱会收到一封激活邮件，点击邮件中的激活链接，进入后，输入前面分配的一样的apache密码，登录，进入界面

![](http://dl2.iteye.com/upload/attachment/0096/7591/b59b8f76-38c4-3447-9df9-391d9be554cd.jpg)  
   
![](http://dl2.iteye.com/upload/attachment/0096/7595/83738b85-ee6d-3a15-820f-ce9c9ef03d12.jpg)  
 在“Full Name”中输入你的名字的全拼，点击“Save Changes”。

![](http://dl2.iteye.com/upload/attachment/0096/7597/3ad3dbcb-e4b7-3d10-b4bc-20d73d029bab.jpg)

 

接下来，配置你的公钥，在第一步生成SSH Key时，有段问题提示你本地的id\_rsa.pub文件生成在哪的，一般在$HOME/.ssh/下，打开id\_rsa.pub文件，复制内容粘贴到下图位置，点击“Add”，完成gerrit配置key。

![](http://dl2.iteye.com/upload/attachment/0096/7599/677be19e-0b55-3dfc-99e8-471dcfef7c7a.jpg)  
 

 激活你的gerrit账户还剩最后一步：和管理员沟通，让其将你的账户加上需要的权限。

 

注意：一般gerrit服务器，是没有匿名访问权限的，所以，只能通过SSH和HTTP选项卡下提示的命令进行下载。

依次执行以下2个命令，进行授权，如果不执行以上命令，会导致提交到服务器失败。

```
// 在用户bin下面，只有安装Git时需要初始化一次
scp -p -P gerritport yourname@gerritip:bin/gerrit-cherry-pick ~/bin
// 在项目下面，每新下载一个项目都需要执行
scp -p -P gerritport yourname@gerritip:hooks/commit-msg .git/hooks
```