Git/Rebase

Interactive Rebase to merge several commits into one
After you have created a new branch, made changes to the code, and committed several changes in your branch, there may come a time when you would like to merge several of your commits from your local checkout into one commit to send to Gerrit.

The  or   option allows you to change (rewrite) your commit history. For each commit, you can modify and change the commit message, add or remove files, or perform other modifications.

First you need to tell git how far back you want to pull. To get a list of all changes in your branch: git rebase -i origin/master

You can also limit the displayed list of recent changes. means pull the last three commits: git rebase -i HEAD~3

After you type this command, your text editor will display your commits in reverse order and a list of available commands:

pick aa8cf1d Adding method customFilterFunctionGetRiskyCountryCodeScore to GatewayAdapter. pick 38828e2 Adding $wgDonationInterfaceCustomFiltersFunctionsRiskyCountries to donationinterface.php pick be33007 Fix a typo


 * 1) Rebase 95ccd28..be33007 onto 95ccd28
 * 2) 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
 * x, exec = run command (the rest of the line) using shell
 * 1) If you remove a line here THAT COMMIT WILL BE LOST.
 * 2) However, if you remove everything, the rebase will be aborted.
 * 1) If you remove a line here THAT COMMIT WILL BE LOST.
 * 2) However, if you remove everything, the rebase will be aborted.

Since we only want to send one commit to review, we will squash the last two commits into the first. Hence change all but the first "pick" to "squash": pick aa8cf1d Adding method customFilterFunctionGetRiskyCountryCodeScore to GatewayAdapter. squash 38828e2 Adding $wgDonationInterfaceCustomFiltersFunctionsRiskyCountries to donationinterface.php squash be33007 Fix a typo

When you finished picking and squashing and saved the file, another file will open in your text editor to allow you you get to edit and merge your commit messages. Be careful to only keep one of the Change-Id lines and have it be at bottom of the message after one empty line.

It is important to leave the Change-Id for each commit in the message, otherwise Gerrit will not know how to handle the patch.

Your messages from your previous commits will automatically be placed in this message: (mingle-fr-2012-69) Adding a custom filter for risky countries.
 * 1) This is a combination of 3 commits.
 * 2) The first commit's message is:

Adding method customFilterFunctionGetRiskyCountryCodeScore to GatewayAdapter.


 * 1) This is the 2nd commit message:

Adding $wgDonationInterfaceCustomFiltersFunctionsRiskyCountries to donationinterface.php


 * 1) This is the 3rd commit message:

Fix a typo

Change-Id: I33e44ec0d93628d9a53c15e08eb89f352b7d5fe0


 * 1) Please enter the commit message for your changes. Lines starting
 * 2) with '#' will be ignored, and an empty message aborts the commit.
 * 3) Not currently on any branch.
 * 4) Changes to be committed:
 * 5)   (use "git reset HEAD ..." to unstage)
 * 6)       modified:   donationinterface.php
 * 7)       modified:   gateway_common/gateway.adapter.php
 * 1)       modified:   gateway_common/gateway.adapter.php

Remember to put your (updated) summary message in the commit. In this case the new summary message will be: (mingle-fr-2012-69) Adding a custom filter for risky countries.

Note: ''In regards to which Change-Id you want to use, squashing a commit into an existing commit (one that's already in Gerrit), you need to pick the Change-Id that belongs to the one you meant to submit a new patchset for (the surviving commit). If your commits are new and are not in Gerrit, it does not matter which Change-Id you choose.''

If all goes well, you should see a successful rebase message:

[detached HEAD 02f5e63] (mingle-fr-2012-69) Adding a custom filter for risky countries. 2 files changed, 92 insertions(+), 3 deletions(-) Successfully rebased and updated refs/heads/mingle-fr-2012-69.

Afterwards, submit your patch for review: git review

You should see a message like this showing your git review went to Gerrit (in this example, to https://gerrit.wikimedia.org/r/7187 ):

remote: Resolving deltas: 100% (4/4) remote: (W) 02f5e63: commit message lines >70 characters; manually wrap lines remote: remote: New Changes: remote:  https://gerrit.wikimedia.org/r/7187 remote: To ssh://jpostlethwaite@gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface.git * [new branch]     HEAD -> refs/for/master/mingle-fr-2012-69