首页 > 代码库 > Git Gerrit Repo User Manual

Git Gerrit Repo User Manual

 

 

 

 

 

 

 

 

 

Git Repo Gerrit User Manual
Revision History

 

Revision #

Description

Date

Author

0.1

Initial this document

2014/09/05

Deman Lu

0.2

Add First time push Code to Gerrit

2014/09/09

Deman Lu

0.21

Add FAQ

2014/09/09

Deman Lu

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Contents

Preparation....................................................................................................................... 4

Install............................................................................................................................... 4

Git Setup:.................................................................................................................. 4

Git Config:................................................................................................................ 4

Set Commit Template:................................................................................................. 4

Set git ignore............................................................................................................. 4

Install Repo................................................................................................................ 5

Gerrit Config:............................................................................................................ 5

Get First Project................................................................................................................ 7

FAQ................................................................................................................................. 8

No Branch Ready For Upload Error.......................................................................... 8

CONFLICT Error..................................................................................................... 8

Upload MergesError................................................................................................ 9

Repo init Error......................................................................................................... 9

Repo syntax error near unexpected token `newline‘................................................... 9

Repo init Connect Error:.......................................................................................... 9

Everything up-to-date........................................................................................... 9

 

 

 

Preparation

OS: Linux or Ubuntu

Software: Git, SSH, Repo

Install

Git Setup:

$ sudo apt-get install git

$ sudo apt-get install git-core

$ git version // version >= 1.6

 

Git Config:

$ git config --global user.name "deman_lu" 

将user name为你gerrit系统的账号(邮箱地址(全小写的前缀))

$ git config --global user.email "deman_lu@htc.com"     

将user email设置成你htc的邮箱(邮箱地址全小写)

$ git config --global core.editor vim

$ git config --global merge.tool vimdiff

$ git config --global color.ui"auto"

 

Set Commit Template:

$ vim ~/.git-template

Symptom:

Bug ID:

Root Cause:

Solution:

Note:

$ git config --global commit.template~/.git-template

 

Set git ignore

$ vim ~/.gitignore

$ git config --global core.excludesfile~/.gitignore

 

Install Repo

$ cd

$ mkdir bin

$ cd bin

$ PATH=~/bin:$PATH

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~/bin/repo

If you can’t connect google, you can copyrepo from:

\\10.33.8.3\cht000\CHT200\CHT210\CHT211\Trainning\

COS_Android\Git&Repo\bin

$ chmod a+x ~/bin/repo

 

Gerrit Config:

 

Gerrit Web: http://10.33.137.230/project/

Add public Key:

$ ssh-keygen -t rsa

If you have ssh key, you can useit directly。

$ cat ~/.ssh/id_ras.pub

 

Select [Setting] ==> [SSH Public Key]Press Add key, and paste your id_rsa.pub content into edit text then added.

 

 

Add Server host key to known_hosts:

 

$ vim ~/.ssh/known_hosts

Paste the host key from below image showingto known_hosts.

$ vim ~/.ssh/config

host gerrit

user deman_lu

hostname 10.33.137.230

port 29418

identityfile ~/.ssh/id_rsa

 

$ ssh gerrit

 ****    Welcome to Gerrit CodeReview    ****

  HiDeman_Lu, you have successfully connected over SSH.

 Unfortunately, interactive shells are disabled.

  Toclone a hosted Git repository, use:

  gitclone ssh://deman_lu@10.33.137.230:29418/REPOSITORY_NAME.git

Connection to 10.33.137.230 closed.

 

If you want to see more detail:

http://10.116.121.47/mediawiki/index.php/Git_Repo_Gerrit_User_Manual

Get First Project

Using following command to get repository.

$ repo init -ussh://deman_lu@10.33.137.230:29418/manifest.git -mteam1.xml

The highlight is the manifest.xml,please connect Administrator to getyour manifest.xml

If you just want to do some practices, youcan ignore it and it will download default project.

$ repo sync

 

$repo forall -c "git checkout -bmaster origin/master"

This will create branch master and connectorigin branch origin/master.

Thus, you can push your code toorigin/master

$ repo upload--re=bill_tan,deman_lu 

 

FAQ

No Branch Ready For Upload Error

Check if it is in some branch

$ git branch

If no branch, change to master branch.

$ git checkout master

Modify some files and commit

$ repo upload --re=<User Name>

After doing below thing, you also meetthese error:

Clean the repo and delete ~/.repoconfig

Please according to “Git First Project” stepby step.

 

CONFLICT Error

 

hailong@hailong-Lenovo:~/test/localhost/gerrit/repo/test$repo sync

remote: Counting objects: 5, done

remote: Finding sources: 100% (3/3)

remote: Total 3 (delta 2), reused 3 (delta2)

Unpacking objects: 100% (3/3), done.

From ssh://localgerrit:29418/new/test

  fdcfcac..5f7a5f9  master     -> origin/master

project test/

First, rewinding head to replay your workon top of it...

Applying: m_cm_6.2

Using index info to reconstruct a basetree...

Falling back to patching base and 3-waymerge...

Auto-merging readme.txt

CONFLICT (content): Mergeconflict in readme.txt

Recorded preimage for ‘readme.txt‘

Failed to merge in the changes.

Patch failed at 0001 m_cm_6.2

 

You should manual merge file when reposync.

$ git add readme.txt

$ git rebase --continue

 

UploadMerges Error

 

When repo upload: ![remote rejected] master ->refs/for/master (you are not allowed to upload merges)

Reason: you have doing some merge butgerrit not allow.

Solution: reset your merge and using gitrebase to commit.

$ git reset --hard <commit id>

$ git fetch

$ git rebase origin/master

$ repo upload --re=<User Name>

Repo initError

Repo int: fatal: Cannot get https://code.google.com/p/git-repo/clone.bundle

fatal: error [Errno 104] Connection resetby peer

Solution: $ vim ~/bin/repo  modify REPO_URL=‘http://android.googlesource.com/tools/repo‘

Repo syntax error near unexpected token `newline‘

/root/bin/repo: line 1: syntax error nearunexpected token `newline‘
/root/bin/repo: line 1: `<!DOCTYPE html>‘This problem is that repo’sversion is too old, using a new one.

$ curlhttp://git-repo.googlecode.com/files/repo-1.12> ~/bin/repo

Or copy repo file form other members.

 

Repo init Connect Error:

fatal: Cannot gethttps://gerrit.googlesource.com/git-repo/clone.bundle
fatal: HTTP error 403

When repo init, repo will download codefrom google, so, the reason is you known.

Please try more times or do it later.

 

Everything up-to-date

$ git push showing :every thing up to date,but you also have not push anthing!

$ git push origin master : this will bedenied by gerrit, you can’t push code to git repository directly.

We must push to review repository:

$git push origin HEAD:refs/for/master

 

Git Gerrit Repo User Manual