How do I undo 'git add' before commit?

How Do I Undo 'git add' Before Commit?

If you've added files to the staging area using git add but want to undo this action before committing, you can use the git reset command. This will unstage the files, moving them back to the working directory without making any changes to the files themselves.

Steps to Unstage Files

Unstage All Files

To unstage all files that have been added to the staging area:

git reset

Unstage a Specific File

To unstage a specific file that has been added to the staging area:

git reset <file>

Example:

git reset myfile.txt

Example Workflow

  1. Stage the Files:

    git add myfile.txt anotherfile.txt
  2. Check the Status:

    git status

    Output:

    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   myfile.txt
            new file:   anotherfile.txt
    
  3. Unstage All Files:

    git reset
  4. Unstage a Specific File:

    git reset myfile.txt
  5. Verify the Status Again:

    git status

    Output:

    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   myfile.txt
            modified:   anotherfile.txt
    

Using git restore (Git 2.23+)

In Git 2.23 and later, you can also use the git restore command to unstage files.

Unstage All Files

git restore --staged .

Unstage a Specific File

git restore --staged <file>

Example:

git restore --staged myfile.txt

Summary

To undo git add before committing, you can use the git reset command to unstage the files. If you're using Git 2.23 or later, you can also use the git restore --staged command. Here are the commands for quick reference:

  • Unstage all files:

    git reset

    or

    git restore --staged .
  • Unstage a specific file:

    git reset <file>

    or

    git restore --staged <file>

By following these steps, you can easily undo the git add command before committing, ensuring that only the desired changes are staged. For more in-depth knowledge and practical examples of Git and other coding practices, consider exploring Grokking the Coding Interview on DesignGurus.io, which provides comprehensive courses on essential coding and interview techniques.

TAGS
Coding Interview
CONTRIBUTOR
Design Gurus Team
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Which framework is used in Netflix?
How to explain low-level programming concepts in interviews?
Is Microsoft interview easy to crack?
How long do I need to prepare for a coding interview?
Software Engineering Interviews
Adopting incremental compilation and testing in mental execution
Related Courses
Course image
Grokking the Coding Interview: Patterns for Coding Questions
Grokking the Coding Interview Patterns in Java, Python, JS, C++, C#, and Go. The most comprehensive course with 476 Lessons.
4.6
Discounted price for Your Region

$197

Course image
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
3.9
Discounted price for Your Region

$78

Course image
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
4
Discounted price for Your Region

$78

Image
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.