If you accidentally ran the git add -a and if you want to undo this command, follow the step below:
First of all, check the status by
This will show you the list of the files that are staged. It’s not mandatory but good to check. So you can compare the end of undoing the git add command.
Second, type the following command and hit enter:
git reset .
This will unstage all files or remove all the files from the staging area.
That’s it! See how to remove files from Git.
Now if you run the git status again, you’ll see that you successfully performed git add undo.
See how you can remove a file from the git commit.
How to undo a specific file(s) from git add -A?
In the above section, you learned how to unstage all files. But sometimes you may need to unstage or remove just one or a couple of specific files instead of all files. This is what you will see in this section.
In the following screenshot below, you see that I have all (three) files staged. Imagine, I need to undo just one file which is “script.js.”
To do that, I have to type the following command and hit enter:
git reset script.js
This will reset the
git add -A command and remote the script.js from the stage (as you see below).
If you need to unstage two files, use the following command:
git reset script.js style.scss
In the same vein, you can unstage any number of files followed by space and then add the file name including the extension.
Note that if you want to remove a file from the stage that lives in a folder, you have to include the path of the file. For example, I have a file named “app.php” that lives in the “vendor” folder. Also, I performed a
git add -A command. As you see in the screenshot below.
To remove the file (vendor/app.php), you have to specify the path like this:
git reset vendor/app.php
This is how you do it.
Learn more about Git
- What is Git and why it is used?
- How to install Git on Windows & Mac?
- How to use Git with Visual Studio Code?
- How to use Git and GitHub?
- What is the difference between Git and GitHub?
- How to connect local Git to a remote server?
- How to change Git remote origin URL?
- How to create a Git repository on GitHub?
- Git add all (stage all changes)
- How to undo the git add -A command?
- How to undo the last Git commit?
- How to change the git commit message?
- How to remove or unstage a file from Git commit?
- How to git push after rebase?
- Git switch branches: How to checkout the git branch?
- How to merge a git branch to master?
- Git branch: create, checkout, merge, list, command, delete & push
- How to clone a Git repository?
- How to git pull to override the local project?
- How to remove file from Git?
- When should you use git rebase?
- Git commands & explanation (downloadable cheatsheet included)
- How to create GitHub Pages?
In this post, I tried to explain all the real cases that you need to deal with undoing git add -A. Also, these are the cases that I came across in practical life. If you do not find the answer to your questions which is related to this post, please let me know.