How Do I Undo ‘Git Add’ before Commit?

Better Stack Team
Updated on June 21, 2024

To undo a git add command before committing your changes, you can use the git reset command. Here's how you can do it:

Step 1: Check the Status

First, check the status of your files to see which ones you've added:

 
git status

This will show you which files are currently staged (added) for commit.

Step 2: Undo the git add

To unstage a file that you previously added with git add, you can use:

 
git reset <file>

Replace <file> with the name of the file you want to unstage. If you want to unstage all files, you can use:

 
git reset

This will unstage all files that you've added but not yet committed.

Step 3: Check the Status Again

After running git reset, you can check the status again to ensure that the files are no longer staged:

 
git status

The files that you've just unstaged should now appear as "Changes not staged for commit".

Notes:

  • git reset will only unstage the changes; it won't discard any modifications you've made to the files.
  • If you want to completely discard the changes in a file that you've added but not yet committed, you can use git checkout -- <file>.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.