Gerrit/split a submitted change

WORK IN PROGRESS

Sometime people submit huge patches that would have been better submitted as smaller patches. This page will help you discover how to split a submitted change and resubmit it properly in Gerrit. This page use a real world case which happened when we migrated from subversion to git back in March 2012, it is based on which introduce three different changes: a caching helper, a way to format time duration and some double quotes to single quote transformation.

The protocol is really easy, fetch the change, create a new branch and cherry pick the change on top of it. Then add only the chunks you are interested of. Repeat the same process for all parts of the change.

Get the code
Make sure you are up to date with the main repo:

git checkout master git pull --rebase

The next thing we want to do is actually fetch the code from Gerrit. The easiest to do so is to use git-review:

git:master)$ git-review -d 3497 Downloading refs/changes/97/3497/5 from gerrit into review/catrope/cachedpage Switched to branch 'review/catrope/cachedpage' git:review/catrope/cachedpage)$

Then find out the commit sha1 introduced by that change using the git log command. We simply have to output commits which makes HEAD different from master:

review/catrope/cachedpage)$ git log --oneline master..HEAD 367d8f5 Resubmit the entire SpecialCachedPage/formatDuration saga as one big com review/catrope/cachedpage)$

Now create the topic branch and apply the patch locally git:review/catrope/cachedpage)$ git checkout master -b cachedpage Switched to a new branch 'cachedpage' git:cachedpage)$ git show 367d8f5 | git apply - $ git status no changes added to commit (use "git add" and/or "git commit -a") git:cachedpage)$
 * 1) On branch cachedpage
 * 2) Changes not staged for commit:
 * 3)   (use "git add ..." to update what will be committed)
 * 4)   (use "git checkout -- ..." to discard changes in working directory)
 * 5) 	modified:  includes/AutoLoader.php
 * 6) 	modified:  languages/Language.php
 * 7) 	modified:  languages/messages/MessagesEn.php
 * 8) 	modified:  languages/messages/MessagesQqq.php
 * 9) 	modified:  maintenance/language/messages.inc
 * 10) 	modified:  tests/phpunit/languages/LanguageTest.php
 * 11) Untracked files:
 * 12)   (use "git add ..." to include in what will be committed)
 * 13) 	includes/CacheHelper.php
 * 14) 	includes/actions/CachedAction.php
 * 15) 	includes/specials/SpecialCachedPage.php
 * 1) 	includes/CacheHelper.php
 * 2) 	includes/actions/CachedAction.php
 * 3) 	includes/specials/SpecialCachedPage.php