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.
For your further reading, I have linked the following post that is very related to this one.
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.