Logo
Logo
Home
Archive
AI Agent Notes
Advertise
YouTube
Login
Sign Up
Logo
  • Home
  • Posts
  • 🦥How to Uncommit Your Crimes

🦥How to Uncommit Your Crimes

Aug 4, 2026

Hello friends!

Welcome to another issue of Sloth Bytes. I hope you’re having a great week.

1,000+ Claude Prompts Top Professionals Actually Use at Work

Claude can be your analyst, editor, and strategist.

But most professionals are using it to fix grammar.

These 1,000+ Claude prompts take it from grammar tool to your most powerful AI work assistant.

Sign up for Superhuman AI and get:

  • 1,000+ ready-to-use Claude prompts to get real work done in minutes — researched, tested, and used by professionals at Google, Microsoft, and NASA

  • Superhuman AI newsletter (4 min daily) so you keep learning new AI tools and skills to stay ahead in your career — the prompts are just the beginning

Claim your free prompts

Your next 100 customers are already in Apollo

Find, reach, and close your perfect deals — without juggling five tools or hiring more reps.

Apollo gives you everything you need to build real pipeline, fast. From inbound to outbound, first touch to close.

All in Apollo.

Sign up for free

Git is great because it remembers every change you make.

But it’s also terrible because it remembers every change you make.

Some code changes are better left forgotten.

  • Maybe you edited the wrong file.

  • Maybe you staged your secret .env file.

  • Maybe you’ve already pushed 50 “fix” commits, and your history now looks like this:

git commit -m "final fix, it actually works this time, I swear"

Eventually, you’ll make one change so diabolical that you have to undo it.

So you search “how to undo something in Git,” and Git gives you three commands that sound like they do the same thing:

  • git restore

  • git reset

  • git revert

That is not very helpful. So what’s the difference?

Well, Git has an official comparison, but its documentation isn’t the friendliest, so here’s the simple version:

  • git restore changes files in your working directory or staging area.

  • git reset moves your branch to an earlier commit and can change your staged or local files.

  • git revert creates a new commit that reverses an older commit without deleting it from history.

The rule you should remember is:

  • Changed a file? Use git restore.

  • Made a local commit? Use git reset.

  • Already pushed it? Use git revert.

That rule handles most Git emergencies, but let’s go through the details before someone runs --hard and ruins everything.

First, You Need to Understand Git’s Three Areas

Before choosing an undo command, you need to know where your mistake currently lives.

Git tracks your work in three main places:

  1. Working directory: The files you are currently editing.

  2. Staging area: The changes waiting to enter your next commit.

  3. Commit history: The snapshots you already committed.

Think of it like writing an email:

  • The working directory is the email draft you’re currently editing.

  • The staging area is the draft sitting in your outbox, ready to send.

  • A commit means you hit send.

Unfortunately, Git does not include one universal “undo” button.

Instead, it gives you three different undo commands.

git restore: Undo Changes to Files

Use git restore when your mistake is still inside a file and has not become a commit.

Let’s say you changed app.js, added 40 lines of code, and somehow made the app worse.

Welcome to the club.

To discard those unstaged changes, you would run:

git restore app.js

This replaces your working copy of the tracked file app.js with Git’s stored version.

Warning: Those uncommitted changes are removed. Git’s documentation warns that restoring a modified file can permanently discard local work.

So before running this command, ask yourself:

Can I fix this, or do I truly want to discard it?

How to Unstage a File in Git

Alright, so maybe your code changes were actually good.

You entered a flow state and started writing the greatest code known to mankind.

Now you’re ready to commit everything:

git add .

…and immediately realize you didn’t just stage your code.

You also staged your .env file.

Great.

Now what? How do you remove one file from the staging area without deleting all the beautiful code you just wrote?

Luckily, you read Sloth Bytes and already know exactly what to run:

git restore --staged .env

This unstages the file without deleting your changes.

Your .env file leaves the staging area, but everything inside it stays untouched on your computer.

You should probably add it to a .gitignore file too, unless you enjoy accidentally leaking API keys.

Restore Summary

git restore app.js          # Discard unstaged changes in app.js
git restore --staged .env   # Unstage .env but keep its changes

git reset: Undo a Local Commit

Now let’s say you already committed your mistake and you haven’t pushed it yet.

The good news is that this is still easy to undo, and only you can see your terrible crime.

Since you committed it, your history currently looks like this:

A — B — C
        ↑
       HEAD

Commit C is your latest commit. Y’know the terrible one.

To undo it and move your branch back one commit, you can use:

git reset HEAD~1
  • HEAD means your current commit.

  • HEAD~1 means one commit before it.

After you run the command, your history will look like this:

A — B
    ↑
   HEAD

Commit C is no longer part of the branch’s visible history.

Like it never happened.

However, what happens to the code depends on which reset mode you use:

  • Soft reset

  • Mixed reset (the default)

  • Hard reset

There’s a few more reset options, but these are the most common ones.

Soft Reset: Undo the Commit, Keep Everything Staged

git reset --soft HEAD~1

This removes the latest commit from the branch but leaves all of its changes in the staging area.

Use this when:

  • You committed too early.

  • You want to change the commit message.

  • You forgot to include another file.

  • You want to combine the changes into a better commit.

Basically, the commit disappears, but all the ingredients remain neatly arranged on the counter.

Mixed Reset: Undo the Commit, Keep the Changes Unstaged

git reset HEAD~1

This is the default --mixed reset.

It removes the commit and keeps the code changes, but those changes return to your working directory as unstaged edits.

Use this when you want to reorganize the changes, edit them further, or split one giant commit into several smaller ones.

Hard Reset: Delete the Commit and Its Changes

git reset --hard HEAD~1

This moves your branch backward and updates both the staging area and working directory to match.

In plain English: The commit disappears, and so does the code.

BE CAREFUL WITH HARD RESETS

--hard can overwrite local files and permanently destroy uncommitted changes. It is one of the few Git operations that can genuinely delete work rather than hiding it somewhere.

I recommend creating an emergency backup branch before using it:

git branch backup-before-reset

Then run the reset.

Creating that branch takes two seconds and can save you from spending the next two hours trying to find the deleted work.

Can I undo git reset --hard?

A commit removed from the branch may still be recoverable through Git’s reflog.

However, uncommitted changes overwritten by a hard reset may be permanently lost. Do not treat the reflog as a substitute for checking what a destructive command will do.

Reset Summary

git reset --soft HEAD~1 # Undo the commit and keep changes staged
git reset HEAD~1 # Undo the commit and keep changes unstaged
git reset --hard HEAD~1 # Undo the commit and discard its changes

Use reset for commits that have not been shared with other people.

Reset changes the branch’s history. If teammates already pulled the commit, rewriting that history can turn your minor mistake into everyone’s minor mistake.

git revert: Safely Undo a Pushed Commit

What happens when the bad commit is already on GitHub and all your teammates can see your crime?

Do not immediately reset the branch and force-push it.

Funny enough, that technically does work in some situations, but it rewrites shared history.

Anyone who already downloaded the original commits may now have a different timeline from yours.

Instead of resetting, you would revert the commit with:

git revert HEAD

Or, to revert a specific commit:

git revert a1b2c3d

Unlike reset, revert does not delete the original commit.

Instead, it creates a new commit that reverses the changes introduced by the old one.

Before:

A — B — C

After reverting C:

A — B — C — D

Commit C contains the mistake.

Commit D reverses it.

The history remains intact, which means your crime is still there, but at least your teammates can pull the new commit without Git experiencing an identity crisis.

When Should You Use git revert?

Use it when:

  • The commit was already pushed.

  • Other developers may have pulled it.

  • You are working on a shared branch.

  • You want a clear historical record of both the mistake and the fix.

  • You enjoy accountability for some reason.

git revert is usually the safest option for undoing public history.

Git Reset vs Revert vs Restore

Here is the whole article compressed into one table:

Situation

Command

Discard unstaged changes in a file

git restore app.js

Unstage a file but keep its changes

git restore --staged .env

Undo the latest local commit and keep changes staged

git reset --soft HEAD~1

Undo the latest local commit and keep changes unstaged

git reset HEAD~1

Delete the latest local commit and its changes

git reset --hard HEAD~1

Safely reverse the latest pushed commit

git revert HEAD

Safely reverse a specific pushed commit

git revert a1b2c3d

The easiest way to choose is to ask two questions:

Has it been committed?

If no, you probably need git restore.

Has the commit been pushed or shared?

  • If no, git reset may be appropriate.

  • If yes, use git revert.

Bonus: What If Only the Commit Message Is Wrong?

Maybe your code is fine, but your commit message says:

git commit -m "fixed teh buton"

Well, that’s embarrassing.

We can’t have typos around here, that’s too human.

Luckily, you don’t need to reset the entire commit.

Instead, you can amend the commit:

git commit --amend -m "Fix the login button"

Amending replaces the most recent commit with a new one, so it is best used before that commit has been pushed or shared.

If you already pushed it, well… your choices are accepting the typo or doing a hard reset and force-pushing.

You’d be surprised how many people would rewrite history over one typo.

Anyways, that’s all from me!

If version control still feels confusing, read my Understanding Version Control issue next.

Have a great week, be safe, make good choices, and have fun coding.

If I made a mistake or you have any questions, feel free to comment below or reply to the email!

See you all Thursday or Friday.

Hopefully…

What'd you think of today's email?

  • 🦥 Amazing! Keep it up
  • 🦥 Good, not great
  • 🦥 It sucked

Login or Subscribe to participate

Want to advertise in Sloth Bytes?

If your company is interested in reaching an audience of developers and programming enthusiasts, you may want to advertise with us here.

Keep Reading

envelope-simple

Join 50k+ developers and become a better programmer and stay up to date in just 5 minutes.

© 2026 Sloth Bytes.
beehiivPowered by beehiiv