OpenDaylight uses for code review prior to merge. So what if you want to contribute a change based on a Gerrit that has not yet been accepted and merged into Gerrit?
(NOTE: Do not use this method to merely make corrections to your Gerrit that has not been merged. The right method for that is to amend your commit with the same ChangeId. This method is primarily useful for building on *someone else’s* commit that has not yet been merged
Turns out, it’s actually pretty easy. Let’s walk through an example.
showed some tabs (rather than spaces) for indents
ands some trailing whitespace.
Not a big deal, but also not pretty. At the time, is still being code reviewed, it’s not merged with master branch. I’d like to go ahead and fix the whitespace issues without waiting for the merge.
To do this, I start by looking up the URL to fetch into my local git repo:
and fetch it:
localhost:controller hagbard$ git fetch https://git.opendaylight.org/gerrit/controller refs/changes/93/393/5 && git checkout FETCH_HEAD remote: Counting objects: 29, done remote: Finding sources: 100% (15/15) remote: Total 15 (delta 5), reused 15 (delta 5) Unpacking objects: 100% (15/15), done. From https://git.opendaylight.org/gerrit/controller * branch refs/changes/93/393/5 -> FETCH_HEAD Note: checking out 'FETCH_HEAD'.
You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name HEAD is now at 261f59d... Fix for bug 24.
As it turns out I’m not on any branch right now, because I’m on a detached HEAD:
localhost:controller hagbard$ git status # Not currently on any branch. nothing to commit, working directory clean
Since I’d like to be able to wander off an work on something else and still get back to my work here, I follow the helpful
advice from Gerrit and create a topic branch:
localhost:controller hagbard$ git checkout -b bug24trailingwhitespacefix Switched to a new branch 'bug24trailingwhitespacefix'
And check to see that I’m on it.
localhost:controller hagbard$ git status # On branch bug24trailingwhitespacefix nothing to commit, working directory clean
I then make my changes, fixing the whitespace issues, and check to see what files I need to add to my commit:
localhost:controller hagbard$ git status # On branch bug24trailingwhitespacefix # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java # no changes added to commit (use "git add" and/or "git commit -a")
Add the the indicated modified file:
localhost:controller hagbard$ git add opendaylight/arphandler/src/main/java/org/opendaylight/controller/arphandler/internal/ArpHandler.java
localhost:controller hagbard$ git commit --signoff [bug24trailingwhitespacefix f9f0598] Fixed whitespace for Gerrit 393 1 file changed, 6 insertions(+), 6 deletions(-)
And push to refs/for/master
localhost:controller hagbard$ git push ssh://firstname.lastname@example.org:29418/controller.git HEAD:refs/for/master Counting objects: 25, done. Delta compression using up to 8 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (13/13), 1.10 KiB, done. Total 13 (delta 3), reused 0 (delta 0) remote: Resolving deltas: 100% (3/3) remote: Processing changes: new: 1, refs: 1, done remote: remote: New Changes: remote: http://git.opendaylight.org/gerrit/394 remote: To ssh://email@example.com:29418/controller.git * [new branch] HEAD -> refs/for/master
As you can see that the bottom, I’ve created Gerrit 394 .
If we go look at we can see that it’s dependent on Gerrit 393 , meaning that it can only be merged *after* :
Let me know in the comments if this has been helpful 🙂