Skip to content

Instantly share code, notes, and snippets.

@amaslenn
Last active August 29, 2015 14:07
Show Gist options
  • Save amaslenn/c1e5218456bfd8d17af4 to your computer and use it in GitHub Desktop.
Save amaslenn/c1e5218456bfd8d17af4 to your computer and use it in GitHub Desktop.
Git and Gerrit

Git and Gerrit

Short story of two tools

First push

Prerequisites:

git clone <repo>
cd <repo>
git checkout work-branch
# work work work
git add <changed files>
git commit

Simply do:
git push origin HEAD:refs/for/master (you should stay on your work-branch)
or
git push origin work-branch:refs/for/master (you can do it from any branch you want)

Fixing previous commit

Prerequisites:

  • you've commit code (following previous steps from previous part)
  • someone reviewed it and set Code Review-1/-2 or Verified-1

Your steps (assuming you did nothing in your working branch since push):

git checkout work-branch
# work work work
git add <changed files>
git commit --amend

Don't forget to add Change-Id from Gerrit's change. Your commit message should look like follow:

Finished really cool and important feature

Change-Id: I859775bc0412c4a2a6ab8a8f71f469dd52d2dc0a

Then simply:
git push origin HEAD:refs/for/master

Removing dependency from Abandoned commit

Follow the white rabbit:

git checkout master
git pull origin master
git checkout work-branch
git rebase master
# fix conflicts if exist
[git commit --amend]

See Fixing previous commit to make sure your ammend commit is OK. Then push your commit.

Creating dependency from not yet merged commit

Follow the red label:

git checkout -b new-branch <parent of refs/changes/22/13422/1>
git fetch <repo> refs/changes/22/13422/1
git merge FETCH_HEAD
git cherry-pick <commit from work-branch>
# fix conflicts if exist

Notes:

  • you can find commands 2 and 3 on Gerrit page.
  • refs/changes/$1/$2/$3:
    • $1 is last two digits of $2
    • $2 is real Gerrit's change id (displayed in browser)
    • $3 patch set id

See Fixing previous commit to make sure your ammend commit is OK. Then push your commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment