Oscar the owl and Vershd logo

How to Git Reset Effortlessly

The Problem

Although amending a previous commit is trivially simple and only requires you to type git commit --amend, what happens when your needs are far greater? This is when git reset steps in.

You might have multiple commits to undo, keeping the existing working files, then alter some of those files, and finally make a new commit.

The Solution

In this example, the last three commits you made to fix something are looking quite dodgy, and your boss is getting antsy about how quickly you can release that bug fix. Typical.
This removes the latest three commits.  It’s identical to: git reset --mixed HEAD~3.
The reset command will copy the old commit message to a file called .git/ORIG_HEAD which you can use later:
 git reset HEAD~3 
Or use this, which will wipe out all your existing working files:
git reset --hard HEAD~3
Or use this, which leaves both the index and all your working files unchanged:
git reset --soft HEAD~3
Now edit your files as you wish (the latest commit is currently b2819de):
... Edit as you wish...
This adds, one by one, the specific working files you wish to have in the new commit:
git add where-is/my-pay-rise.txt
Or use this, which adds all of your working files (it’s identical to: git add –a):
git add .
Finally, this creates a new commit and opens a text editor with your original commit message.
Edit it as you wish, close the message, and the commit will be performed:
git commit -c ORIG_HEAD

Zero stress Git

Vershd is an effortless Git GUI that boosts software development. It works on Windows, macOS, and Linux. It's free for personal, educational, non-profit and trade union use.

Designed for intermediate and beginner Git users, our unique UI/UX boosts your software development and makes Git simple.

Help & tools

We provide these pages to try to make your programming life easier. Our resources page gives an overview. You can see a full list of our Git tips & tools here.

We have these free tools:

Customers say...

I love any tool that makes my life easier... This is perfect, just the right amount of control. No more, no less. Easy to get started, push and rollback changes... It's a no brainer!
Hayden T.
Oscar the owl and Vershd logo
 © 2021 Blightysoft
Made in England
St. George's flag of England, the Union Jack flag of the United Kingdom, the European Union flag, and the United Nations flag.
chevron-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram