NullTerminator All articles
Developer Culture

Git Amnesia: The Horror of Discovering You've Been Wrong This Whole Time

NullTerminator
Git Amnesia: The Horror of Discovering You've Been Wrong This Whole Time

Photo: stressed programmer staring at computer screen terminal dark room, via l450v.alamy.com

There is a specific kind of dread that has no name in the English language. German probably has one — they usually do for the worst emotional experiences. It's the dread that arrives at the exact moment you run [git](https://en.wikipedia.org/wiki/Git) log --oneline and realize the last six commits you made are sitting on main instead of feature/user-auth-v2, where they were absolutely supposed to be.

This is git amnesia. And it happens to everyone. Even the person on your team who acts like it doesn't.

The Workflow That Felt Fine Until It Wasn't

Here's how it goes. You sit down Monday morning, coffee in hand, full of ambition and the specific optimism that only exists before you've opened your laptop. You git pull, you start typing, and three hours later you've written the best code of your career. Clean functions. Meaningful variable names. Comments that would make a documentation purist weep with joy.

And then you glance at your terminal prompt.

main.

Not feature/user-auth-v2. Not even hotfix/the-thing-from-last-tuesday. Just main. Bare, unforgiving, accusatory main.

The coffee goes cold. The optimism evaporates. You are now in crisis management mode, which is a generous term for what is actually just typing increasingly desperate git commands while refusing to breathe normally.

Ctrl+Z Won't Save You Here

The instinct, of course, is to reach for the universal undo. Every operating system has trained us since childhood to believe that Ctrl+Z fixes mistakes. Deleted a paragraph? Ctrl+Z. Accidentally dragged a file into the wrong folder? Ctrl+Z. Made a series of irreversible decisions that have now compromised your team's release schedule? Ctrl+Z.

Except git doesn't work like that. Git is not a forgiving parent. Git is a meticulous archivist who has documented everything you've ever done and will happily surface it during the worst possible moment — like when your tech lead asks why the commit history looks like it was authored by someone having a personal crisis.

The actual fix involves git reset, git cherry-pick, possibly git reflog if you've really gotten into it, and a quiet inner monologue that cycles through denial, bargaining, and something resembling acceptance. The reflog, bless it, is basically git's version of a black box recorder — it tracks everything, including the mistakes you were hoping to quietly bury. It is simultaneously your salvation and your confessor.

The Staging Area Is a Trap With Excellent Marketing

If accidental commits are the dramatic act one of git horror, the staging area is the slow-burn psychological thriller of act two. The index — that cheerful intermediate space between your working directory and your commit history — has an uncanny ability to contain exactly the wrong files at exactly the wrong time.

You git add . because you're moving fast and the standup is in ten minutes. Totally reasonable. Except . doesn't discriminate. It added your feature code, yes, but it also staged your .env file, three debug scripts you were definitely going to delete, and a test file containing the string REMOVE THIS BEFORE COMMITTING in the first line. In large capital letters. Like a warning label you ignored.

git diff --cached exists specifically to prevent this. It shows you exactly what you're about to commit before you commit it. It is one of the most useful commands in the git ecosystem. Most developers discover it approximately six months after they needed it.

Debugging Code Has a Way of Becoming Permanent

There's a particular subspecies of accidental commit that deserves its own category: the debugging artifact. The console.log('FINAL TEST DO NOT PUSH'). The // TODO: delete this before PR. The temporary hardcoded API key pointed at your personal sandbox environment that you definitely meant to swap out.

These commits have a survival instinct. They slip through code review because reviewers' eyes glaze over after the fifth file. They pass CI because CI doesn't care about your dignity. They land in production, where they sit quietly until someone opens the browser console during a client demo and sees FINAL TEST DO NOT PUSH printed forty-seven times in red.

The correct response is git rebase -i to squash or edit commits before they ever touch a shared branch. The actual response, for most of us, is a follow-up commit titled cleanup that patches over the evidence and hopes nobody reads the diff.

Making Peace With the Reflog

Here's the thing nobody tells you when you're learning git: almost nothing is actually permanent. The reflog keeps a rolling log of every state your HEAD has ever pointed to, giving you a roughly 90-day window to recover from nearly any mistake. Deleted a branch? It's probably in the reflog. Force-pushed over something important? Reflog. Committed six hours of work to the wrong place and then panicked so hard you made it worse? Reflog.

Git is not trying to punish you. Git is a very thorough record-keeper who happens to surface information in the most emotionally inconvenient order possible. Once you stop fighting that and start learning to navigate it — git reflog, git reset --hard HEAD@{n}, breathe — the whole system starts to feel less like an adversary and more like a paranoid but ultimately helpful colleague.

The Ctrl+Z you're looking for exists. It just requires knowing which three commands to type, in which order, while your hands are still shaking.

And maybe switching to a branch before you start next time. Just a thought.

All Articles

Related Articles

The Pull Request That Time Forgot: A Survivor's Guide to Review Purgatory

Scope Creep Has a Body Count: Surviving the Refactor That Never Ends

Scope Creep Has a Body Count: Surviving the Refactor That Never Ends

Maintaining Code You Didn't Write and Don't Fully Understand: A Field Manual

Maintaining Code You Didn't Write and Don't Fully Understand: A Field Manual