A Git story: what to do when you want to give up and revert everything
My team members call me the “git master”.
Because whenever their button-pressing-commit-dragging GUI fails them (which it always does during those massive merge conflicts), they’d ask me to untangle their mess via command line so they could stop banging their heads against the desk, as shown below in a gif.
Except the “git master” screwed up very hard today.
At 1:05pm, I thought to myself: “Just one more would definitely fix it.” It was already the 5th time I merged into the team repository trying to solve the build issue, and I promised my coworker overseas that I’d to unblock him by 5pm.
Oof.
This 5th commit didn’t help. Production host screamed at me with the same error message. What would I even do at this point? I didn’t know how to fix this bug and I needed to deliver. The clock ticked and I kept on wasting my time to see if my former-IC boss sitting across would realize I had been opening one too many merge requests. (And merging them myself with a note of “high priority”.)
“Revert everything and start clean.”
I heard the faintest whisper in my heart.
“Try git reset — hard to the last working commit and push. You’d never know what company loopholes you can find.”
What a great voice of the devil. And I tried it, betraying my core belief as a proper git user. Luckily, company policy protected my sense of integrity by disabling history rewriting ¯\_(ツ)_/¯
2:05pm, I began frantically googling for similar miseries. I knew that I could revert everything, but I wanted NOT to cover up all 10 of my brain farts with 10 more reverts. (Yes, I managed to “ fix” the bug 5 more times since two paragraphs ago.)
“Git revert — no-commit $commitId”
Theoretically, I loved it. But my right hand cramped up while reverting the 6th commit so I gave up and git-reset to the original state. Fun fact, only 1 character in “ — no-commit” is typed by your left hand.
Since you have made it to the end of my rant and daily confession of my git sins. What I did to (somewhat) save my reputation was the following:
“Git revert $commitId” for each commit.
“Git revert -m 1 $mergeCommitId” for each merge.
(If you try simply reverting without -m, git will yell at you on screen in red.)
“Git rebase -i”
Finally, the cherry on top. Please squash (s) all my “fixes” that did not fix anything and cherry-pick (p) the change that will unblock my coworker.
Also fun fact: git gets mad at you if you don’t have a previous commit. So if it complains, just pick “r” for the top commit on the list of f*ck ups. I think the “r” stands for rework or reword.
After the rebase, I was able to aggregate all 10 reverts into a single commit before pushing to team repository.
Lesson of the day: the quickest way to level up git skills is to f*ck up really hard under time pressure. And then write about it. This is what learning is all about anyways.