May 23, 2013

Kata problem: Git wrong commit

Hi there,

This is a Git problem I put up to the office and I really liked practicing the various different ways that people came up with.

I thought to share this, as it could be used in a Git dojo to get the feeling of rewriting the commit history.

As lots of my colleagues pointed out: this is easy to be done because it is a offline branch.

When you share this code with a remote repository it is really complicated to rewrite history, because you need to force the new history on the remote, which can corrupt or lose commits that already exist there and are not in sync.

Here is the problem:

Me and my pair was working with one project on my machine. It uses git to keep track of the files.

The workflow of the project is that the master is always green, we have features on branches to keep track of the work, but we merge it back often.

We were playing one story and it was merged on master already. After we moved the story to validation, we picked up a new story.

One of the QA’s found an IE misalignment on the feature, really simply to fix. So we fixed the issue and committed.

But we forgot to change the branch to master before committing.

We ended up with this state:

$ git branch

  master* search_project

$ git log —graph —decorate —oneline —branches

* 7ff891f (HEAD, search_project) [USL-107] Fix css alignment of the user search box

* 7c5b3c1 [USL-108] Use autocomplete when searching projects

* 7fa2aef [USL-108] Search projects

* 8655896 (master) [USL-107] Search users using autocomplete

The challenge here is to move the commit we created to the right branch.

The end state should be this:

$ git branch

  master* search_project

$ git log —graph —decorate —oneline —branches

* 3e8322a (HEAD, search_project) [USL-108] Search projects

* 1090110 [USL-107] Fix css alignment of the user search box

* cfc2c36 (master) [USL-108] Use autocomplete when searching projects

* 8655896 [USL-107] Search users using autocomplete

Here is the repo in the initial state.

Have fun.