Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert a bad fixup in GIT?

Tags:

git

I am sure there's a bunch of GIT users out there who's had this problem:

  1. Create a branch from master. Let's call it featureX.
  2. Somewhere, while working on featureX, you realize you want to make a fixup of a previous commit:
    • You commit your fix.
    • You do your rebase and squash/fixup.
  3. Later you would like to rebase against your master to incorporate the latest changes into featureX.
  4. Things break because your branches have diverged (the fixup was not done in master). You have a bad day.

This is the second time this has happened to me. The first time, I didn't have very much history in featureX and simply made a new branch off of master. What's your take on this? How would you solve this? Is it possible to git reset a certain reflog? In that case I could undo the rebase and move the fix commit back on top of featureX (using interactive rebase).

I'm sure there are different ways to go about it, but I guess this is a common problem.

like image 856
Ztyx Avatar asked Jul 12 '12 04:07

Ztyx


1 Answers

Yes you can reset any branch to anything that was checked out before (the reflog). Because your fixup is still in FeatureX, the rebase will behave no different than if you don't do the fixup - it only matters if the divergence of master has conflicts with any of the commits in the featureX branch - fixups or not.

Secondly, when people first learn git, the fall in love with the awesomeness of rebasing. But I've gone back to merging. It's simpler, it marks history as it happened and it forces some discipline. Here is my workflow: http://dymitruk.com/blog/2012/02/05/branch-per-feature/

like image 193
Adam Dymitruk Avatar answered Sep 24 '22 14:09

Adam Dymitruk