Oscar the owl and Vershd logo
How to Git reset

How to Git Reset

9th March 2020

This is part of a Git Tips series. For the complete set for beginner and intermediate Git users, see our white paper.

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

The Quickest & Easiest Solution

Do you need a Git GUI that's totally free for personal use? Vershd boosts your software development productivity by making Git simple with a unique UI/UX. It's a Git GUI that prevents errors and creates clarity. This Git client soars over your repository and then swoops down to quickly tackle branches, commits and files. It deals with Git, so you can concentrate on coding.

Get screenshots and a 60 second video of what Vershd, the effortless Git GUI can do for you.
Vershd is the effortless Git GUI for Windows, Mac, & Linux
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