A git revert alternative

26 Aug

We use gitflow for our branching model. Yesterday we ran into an issue where a front-end redesign was finished, merged into develop and pushed to remote, prior to being approved. This would cause a problem if we wanted to create new releases from develop because they would include the front-end redesign that wasn’t ready just yet. The immediate reaction was to use git-revert to rollback each individual commit, but it seemed like a bit of a sloppy solution for 20 or so commits.

The solution we came up with was the following:

  1. branch from the commit prior to the first unwanted commit, we named it develop_new
  2. cherry pick any commits you do want from develop into develop_new
  3. rename develop to feature/redesign
  4. rename develop_new to develop
  5. update .git/config to ensure the renamed branches point to the correct remote references
  6. force push develop to remote
  7. push feature/redesign to remote
This is obviously only a good solution if you catch the problem in time and thus only require a few cherry picks.
A bit of Googling produced a similar alternative using git-rebasehttp://stackoverflow.com/questions/4434787/git-how-to-undo-a-merge

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: