Creating a Patch. Created by Carl Heymann on 2010 Sep 14 1

Similar documents
Getting the Source Code

Continuous Deployment with Gerrit and Jenkins

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

RSARTE Git Integration

Version Control System - Git. zswu

Git tips. Some tips to use Git.

CS 390 Software Engineering Lecture 5 More Git

FAQ Q: Where/in which branch do I create new code/modify existing code? A: Q: How do I commit new changes? A:

git the SCM system Jan-Simon Möller training.linuxfoundation.org

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

The Old World. Have you ever had to collaborate on a project by

Windows. Everywhere else

Git and Gerrit Workflows. Enforcing Manual & Automated Review

Git. A Distributed Version Control System. Carlos García Campos

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

CS 520: VCS and Git. Intermediate Topics Ben Kushigian

Fundamentals of Git 1

RSARTE Git Integration

Git Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

Revision control Advanced git

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

Introduction, Instructions and Conventions

b. Developing multiple versions of a software project in parallel

Best Practices. Joaquim Rocha IT-DSS-TD

Introduction to Supercomputing

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Git Workbook. Self-Study Guide to Git. Lorna Mitchell. This book is for sale at

Change-sets. Basavaraj Karadakal

Software Development I

EGit in Eclipse. Distributed Verzion Control Systems

MOOSE-Based Application Development on GitLab

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 11, 2017

Getting the files for the first time...2. Making Changes, Commiting them and Pull Requests:...5. Update your repository from the upstream master...

Revision Control. An Introduction Using Git 1/15

How to git with proper etiquette

API RI. Application Programming Interface Reference Implementation. Policies and Procedures Discussion

Lab Objective. Lab Assignment. Downloads and Installation

Tizen/Artik IoT Practice Part 4 Open Source Development

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

KTH Royal Institute of Technology SEMINAR 2-29 March Simone Stefani -

How to be a git. Dominic Mitchell

2 Initialize a git repository on your machine, add a README file, commit and push

Github/Git Primer. Tyler Hague

VCS VERSION CONTROL SYSTEMS

1. Which of these Git client commands creates a copy of the repository and a working directory in the client s workspace. (Choose one.

GIT Princípy tvorby softvéru, FMFI UK Jana Kostičová,

Working in Teams CS 520 Theory and Practice of Software Engineering Fall 2018

Git. Christoph Matthies Software Engineering II WS 2018/19. Enterprise Platform and Integration Concepts group

New Contributor Tutorial and Best Practices

Git for Subversion users

Git, the magical version control

A Brief Introduction to Git. Sylverie Herbert (based on slides by Hautahi Kingi)

Git: Distributed Version Control

Version Control with Git

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

Version Control. Version Control

Submitting your Work using GIT

Introduction to distributed version control with git

Beyond git add/commit/push

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Git Like You Mean it. Alan Ott SCaLE 16x March 8-11, 2018

Why? Clean Model Branches Local reflog Flows Doc Ex. Advanced use of Git. Matthieu Moy

May the GIT --FORCE Be With You

Git version control with Eclipse (EGit) Tutorial

IC Documentation. Release 0.1. IC team

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Gerrit

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

git-flow Documentation

GIT tutorial. David Parsons, Soraya Arias, Thomas Calmant November, Preamble 2

Lecture 6 Remotes. Sign in on the attendance sheet!

Outline The three W s Overview of gits structure Using git Final stuff. Git. A fast distributed revision control system

Git. A fast distributed revision control system. Nils Moschüring PhD Student (LMU)

Index. Alias syntax, 31 Author and commit attributes, 334

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

February 2 nd Jean Parpaillon

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 17, 2018

Tips on how to set up a GitHub account:

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

Intro to Github. Jessica Young

Using Git and GitLab: Your first steps. Maurício

Advanced Git. Luc Sarzyniec. Xilopix, February / 88

Agenda. Several projects are using GIT Developer(s) Junio Hamano, Linus Torvalds. Qt Stable release (January 31, 2011)

a handful of Git workflows for the agilist steven harman twitter: stevenharman

Table of Contents. Concepts

Continuous translation with Weblate. Michal Čihař

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

Introduction to GIT. Jordi Blasco 14 Oct 2011

Why? Clean Model Branches Local reflog Flows Doc Ex. Advanced use of Git. Matthieu Moy

Visualizing Git Workflows. A visual guide to 539 workflows

Git Branching. Chapter What a Branch Is

Tutorial 2 GitHub Tutorial

Version Control System GIT

Effective Programming Practices for Economists. 7. Version Control, Part II: Git with a Shared Repository

An introduction to git

Git. Presenter: Haotao (Eric) Lai Contact:

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

Transcription:

Created by on 2010 Sep 14 1

1. Starting a Patch To create a patch, and get it through the review process and into a main branch of a project, you can follow the following steps: Clone the project if you haven't already. Checkout the branch into which you want the change to go. Pull from origin to make sure you have the latest commits for the branch on your machine. Create a topic branch from the target branch. If you have a JIRA, you can name the topic branch after it. E.g.: git clone gerrit:gerrit/training localdir # if you haven't cloned yet cd localdir git checkout master git pull origin # if you have cloned before, and just need to pull in the latest changes git checkout -b TWD-220 You now have a local branch called TWD-001, which is where you will be developing the patch. The local branch points at the same commit as master at this stage. Do your work, and commit often. If you want to make small commits at this stage, you can, but then you'll need to rebase and squash them later. If you want to save the work on the server, you can push the local branch to your sandbox space. git push origin HEAD:sandbox/carl.heymann/TWD-220 At this stage, your local branch has several commits. Initially, you will still be directly ahead of master in the commit tree, but as soon as another patch is Created by on 2010 Sep 14 2

submitted (merged) into master, you won't see master in your direct commit history anymore. Before submitting, you need to get the work squashed into a single commit, which can be reviewed. To do this, use an interactive squash. You can squash on the same branch, or make a new branch before squashing. To rebase the work on the master branch: git checkout -b TWD-220_review git rebase master --interactive At this point, you get an editor screen (e.g. vim), with some text. This is used as instructions for the rebase. It lists all commits that are only in the current branch (in chronological order, top to bottom), with instructions before each commit. Leaving each instruction as "pick" will simply replay the commits in order, creating new commits that follow from the master branch. You can change the instructions, as per the comments on the editor. Changing a "pick" to an "s" will squash that commit into the previous one (but you can merge the commit messages by hand), while "f" fill squash it and throw away the commit message. In this case, we can change it as follows: pick 4dc18bd TWD-220 Demo patch f 2de768c tmp commit # Rebase bb29643..2de768c onto bb29643 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. When you save and exit, the rebase is carried out. If you have conflicts, you will need to fix these and then do a "git rebase --continue", or "git rebase --abort" to go back to the state before the rebase was started. Created by on 2010 Sep 14 3

The new state: The original TWD-220 branch still exists, and the server has a sandbox branch pointing at it as well. However, the new TWD-220_review branch has been created as a separate commit, rebased on master, with all the changes in the TWD-220 commits combined. This new commit is the one we will push for review. To push for review: git push origin TWD-220_review:refs/for/master 2. Performing a Review Now, the review shows up on gerrit, and you can add reviewers. Created by on 2010 Sep 14 4

Adding reviewers cause email to be sent to them, inviting them to review the change. Reviewers can view the changes by clicking on files, e.g. on "hello.txt" in this case. You can add comments by double-clicking on a line, then typing the comment. When you save it, it is still only visible to you (draft), but the server knows about it. It will only be published for all to see once you complete the review. Once you are done looking at files and typing comments, you can complete the review by clicking the "review" button on the change detail screen. Then, you must select radio buttons, to show if you can confirm the following: o o Verified: the change compiles and runs unit testes (verified +1) or not (-1), or if you have no opinion (0). Code Review: the change looks good, and may be submitted to the intended branch (+2) the change looks good, but someone else must decide if it can be submitted (+1) no opinion (0) Created by on 2010 Sep 14 5

the change looks bad, and you'd prefer that it is not submitted, but you won't veto the submit completely (-1) the change may not be submitted (-2) If a change has either a -1 verified or a -2 code review state, it cannot be submitted to the target branch. Furthermore, it requires at least a +1 verified and a +2 code review from any reviewer before it can be submitted. Remember, any developer can set -1..+1 verified and -2..+2 code review states, so all developers have full approval and veto rights on all projects. However, only someone from the relevant leads group can submit the patch to the target branch. NB: don't set Code Review = +2 on your own patches. We cannot enforce this (yet) but we can query for it using the reviewdb database. Once the review is completed, the other reviewers, and the originator get emails. 3. Creating a Second Patch Set To create a second patch set, e.g. after a change was rejected in the review process, you need to get the branch with the commit that was pushed initially. If you still have that branch, you can check it out, e.g. git checkout TWD-220_review 3.1. Getting review code in a local branch If you don't have the branch, then you can create it anywhere. Look for the change ref in the patch detail page. You can create the branch as follows: git fetch origin refs/changes/40/40/1 && git checkout -b TWD- 220_review FETCH_HEAD What happens is the following: You fetch the specific point in the commit tree from gerrit. That point is stored temporarily in the local git repo under the special ref name "FETCH_HEAD" (git does this whenever you fetch on a specific commit). You then create a local branch named "TWD-220_review", with the branch tip pointing at the same commit as "FETCH_HEAD". From this point on, the branch is a regular local branch, and you can continue. Created by on 2010 Sep 14 6

3.2. Changing the Change To prepare the second patch set, you simply go to the topic branch (which has the originally pushed commit for the change) make the changes, then commit with the --amend flag. git commit --amend -C HEAD Amending the commit simply adds the changes you've made to the commit, so there is still only a single commit. The "-C HEAD" tells git to use the same commit message as the HEAD commit, i.e. the commit we're amending, so the commit message is unchanged. If you want to change the commit message, just leave out the -C option and you will get an editor to edit the message. NB: Make sure the change-id in the commit stays the same, so gerrit can correlate the change. If it's not there, you don't have the commit hook set up. Paste the change ID at the end of the commit message, leaving a blank line before it. You can get the change ID line by copying from the change detail screen. To tell gerrit about the patch: git push origin HEAD:refs/for/master Exactly as before. Gerrit creates a patch set, which must be reviewed. At this stage, the repository in our example looks like this: You can see that another change, "CHG-2" has been merged into the master branch since you started working on TWD-220. Gerrit shows the patch as patch set 2 on the same change: Created by on 2010 Sep 14 7

If you look at the file, you can see how it changed from e.g. patch set 1 If the patch is verified and reviewed OK, then the project lead can submit the patch. If there is a merge conflict, gerrit will tell you: "Your change could not be merged due to a path conflict. Please merge (or rebase) the change locally and upload the resolution for review." To fix the conflict, you must rebase the patch branch on master, then submit again. # get the latest master commits from gerrit git checkout master git pull origin # go the review branch and rebase git checkout TWD-220_review git rebase master # solve merge conflicts, then: git rebase --continue # upload the rebased commit git push origin HEAD:refs/for/master Created by on 2010 Sep 14 8

Note that the rebase on master will only work properly if you haven't committed directly to master before. If you have, you will be rebasing on your own version of master. To get your master branch back to tracking origin/master: # First make sure that your working directory is clean.. # Save your master branch under a different branch name git branch savemaster master # Reset your master branch back to the gerrit master branch git checkout master git reset --hard origin/master After this, you can do the rebase as described before. After pushing this (3rd) patch set to gerrit, it must be reviewed and submitted again via the web interface. If this has succeeded, you can see the commit in the master branch. git checkout master git pull origin The tree now looks like this: You can clean up the TWD-220 branch by deleting it, and also the sandbox branch on the server: git branch -D TWD-220 git push origin :sandbox/carl.heymann/twd-220 Note that pushing nothing to a remote branch deletes it on the gerrit server. You can also delete the sandbox branch via the gui (Admin->Projects->select project->branches) 3.2.1. Sample of a Successful Review Sample review Created by on 2010 Sep 14 9

3.2.2. The effect of parallel work, on repo history Doing a lot of independent, parallel work on a repository has the effect of creating merge commits, i.e. commits with multiple parents, which pull different branches together. An example of this is shown here: As you can see, the TWD-219, TWD-225 and TWD-221 work were all done independently, on different review branches, and merged by gerrit on successful submit. Created by on 2010 Sep 14 10