Skip to main content

How to Undo git add

Short answer

To undo git add and remove a file from the staging area without discarding any of your actual edits, run git restore --staged <file> (Git 2.23+) or the older equivalent git reset HEAD <file>. This moves the file back to the 'modified but not staged' state, so your changes in the working directory are fully preserved. To unstage everything in one go, run git restore --staged . or git reset HEAD. This operation is completely safe and reversible — no data is lost, and you can re-stage the file at any time with git add. Use git diff --cached before committing to review exactly what is staged, so you catch accidental additions before they end up in your commit history.

Git does not automatically include changes in a commit: they have to be explicitly added to the next commit, with the git add command.

But sometimes you might change your mind and decide that a certain file should not be part of the next commit. In this short article, we'll answer the question of how to undo adding a change to the staging area, after having used git add before.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Using git restore to Undo git add

Luckily, there's a simple way of undoing a git add: you can simply use the git restore --staged command on the affected file:

git restore --staged index.html

This will remove the file from Git's staging area, making sure it is NOT part of the next commit.

If, at the same time, you also want to discard any local changes in this file, you can simply omit the --staged flag:

Careful: this command can discard work.

git restore index.html

This will undo any modifications in this file since you last committed it. Please be careful with this command: undoing uncommitted local changes cannot be undone!

No Command Line Needed

Undoing "git add" in Tower

In case you are using the Tower Git client, undoing a "git add" is as simple as unchecking the "Status" checkbox for the affected file:

Using git reset to Undo git add

The restore command is a quite recent addition to Git (in version 2.23). If you're using an older Git version, you have to resort to the git reset command to achieve the same results:

git reset index.html

Just like git restore, this will remove the file from Git's staging area and thereby NOT include it in the next commit. The local changes themselves are not affected by this command.

Learn More

Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!