sourceTree+gerrit management code

The first time I came into contact with gerrit, I would be very repelled by this code management method, especially those who are used to using sourceTree with git for code management. If you are unhappy, you will have to write the code. Our goal is to make the development process cool.

About the knowledge of gerrit, move here to learn: [Gerrit] Gerrit Workflow and User Manual

Unfamiliar students can continue to study after reading the above article.

The main problems we encountered are as follows:

1 Before pulling the code for the first time, you need to configure the local git environment

1 Some functions of sourceTree can not be used, which makes people uncomfortable. For example, you cannot push directly

2 In the process of submitting code, if there is a conflict, gerrit does not give merge permission by default. How to deal with it?

 

First, the first git configuration

1 Set Git username and email

 
$git config --global user.name tao.wang

 
$git config --global user.email [email protected] 

2 Verify

$git config --global user.name 
 // tao.wang

$git config --global user.email [email protected] // [email protected]

3 Create SSH Key public and private keys and upload gerrit. This step is familiar to everyone. Don't know google.

4 Configure local gerrit

Create a config file in the previously created .ssh folder (or copy the configured config file directly), the content of the config file (note that the user name is replaced with your own account name, the port port defaults to 29418, some companies will change it, pay attention to replace available ports):

host gitserver hostname 172.16.99.xx 
user tao.wang
port 29418  

host gerrit
hostname 172.16.99.xx 
user tao.wang
port 29418
KexAlgorithms +diffie-hellman-group1-sha1 

 

Second, sourceTree cooperates with gerrit
The main problem is that we can't push directly in the upper left corner of sourceTree, we need to operate in the terminal, and we can't use 
git push origin master
 

Why is this? If you have read the article [Gerrit] Gerrit Workflow and User Manual , you will know that gerrit has added a codereview process. So it will depend on a temporary branch, and we need to submit the code to this temporary branch.

So, pull the code with the following command:

git push origin HEAD:refs/for/master
 but! Some students just like to use sourceTree, which is beautiful and powerful, but suddenly can't push the code, very panic!
In order to solve this problem, I read many posts on the Internet, among which this post on Stack Overflow has the most standard answer:  https://stackoverflow.com/questions/9917645/push-to-gerrit-using-sourcetree .
However, practice has proved that the first solution is not available. that is
git config remote.origin.push refs/heads/*:refs/for/*

Modify the config file, invalid!

The second is to create a custom action, execute the script, and the script pushes correctly. Facts have proved useful!

1 Use xcode to create a shell script with the following content

#!/bin/sh

#  push.sh
#KeepRunning
#
# Created by Wang Tao on 2018/4/27 .
#  Copyright © 2018年 niujinfeng. All rights reserved.

# Get the current branch name
branch=`git symbolic-ref --short -q HEAD`
# push review
git push origin HEAD:refs/for/${branch}

 

2 Create a custom operation in sourceTree, the configuration is as follows, the parameter column is the path where the script is located, please replace the correct path

3 Then when pushing, do not select the push in the upper right corner, but select the custom operation push gerrit.
 
 Perfect solution, now you can throw away the terminal.
 
3. Conflict Resolution
 
Because gerrit does not have merge permissions by default, after the conflict, even if it is resolved locally, an error will still be prompted when uploading. How to do it? At this time, reset the branch to the last node without conflict, stash your own changes, and temporarily store them. Then pull the latest code, there will be no conflict at this time, because your workspace is clean, and then apply stash, even if there is a conflict at this time, you can resolve it locally and submit it. There are many ways of conflict resolution, this is the one I use the most, and everyone needs more practice.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324992267&siteId=291194637