If you have added files to the stage area using the git add command but you want to remove or upstage them, you can simply make use of the git restore command,
Intrestingly if you run the git status command and you have some files in the staging area, the command itself shows hints on how to restore files,
% git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: Sample.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
Main.java
So, to unstage the file Sample.java execute the below git command,
% git restore --staged Sample.java

How to unstage all files?
Just add a . to restore all files that are staged,
% git restore --staged .
❗️Note: If you have a staged file and have made modifications to that file and you restore it, the local changes will be discarded i.e. lost, so be careful (unless you are using an IDE that maintains a history of a file like - Eclipse, VS Core or IntelliJ
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!