I had one of those "Oh shit, Git!" moments this past weekend...
Mine was that I made a necessary change, and since it was pretty minor (really a typo fix of sorts) I just went ahead and did it in the main
branch. NBD. Commit
, push
, and pull
on the remote host, and all is good.
Except I have a big feature dev branch in parallel and I need to pull this minor fix into it. Normally this is not a big deal, because I'd have done separate dev in another feature branch and merge
it in as well...but this time it was done in main
and I got confused/sidetracked by the (normally helpful) output in Git Graph.
Long story short, I ended up doing some combination of rebase
, merge
, and revert
. Not in that order. It was a dark time, and ultimately/somehow in my related panic I managed to push
this up to github on the main
branch (and subsequently pull
ed it into production).
At this point I would normally crawl in a hole. Ugh. But for Future Me's sake, I write this as a reminder.
Time for the Big Guns
I have now dug quite the hole. Production is broken, and I have some weird-ass gnarled mess between the local branches. Time to make some HARD
choices.
I've managed to wrap my head around how I really want this to work out, so first off is to fix main
(and subsequently production).
On the main
branch, locally (and then remote):
git reset
[last good commit hash
]
- [Re-]Make fixes,
commit
git push -f origin main
git pull
(remote)
git reset --hard
[new origin/HEAD hash
] (remote)
Production and main
are now fixed. Woohoo!
Switch over to the feature dev branch:
git merge main
- Double-check the desired changed stuff from
main
is present
Relax, It's Fixed!
Git Graph (a super useful VSCode plugin if you're not already using it) verifies what I expect, and all is now well. Time to relax.
I don't know why I thought rebase
would be the right move here, other than getting temporarily confused by the graph lines in Git Graph (combined with the disparate branches). I knew better than this, but clearly I'm a little out of practice on things.
And this, kids, is why you do dev work (minor as it may be) in separate branches from your primary (or main/production). The mere presence of the other branch would've easily made my mind click in the proper way.
Ah well, it's fixed now. Time for a beer!