git add for All Files
If you want to unstage all files you've added, you can use one of the following commands:
- Using a basic
git resetwithout any arguments:
HEADwith the reset, which refers to the current commit:
git reset HEAD
git resetwith no arguments, which implicitly targets
Any of these commands will unstage all the files you've added, but won't alter the actual changes made to the files.
git add for a Specific File
If you only want to unstage a specific file, you can do so by including the file's name in the reset command:
- Basic reset with the filename:
git reset <filename>
HEADwith the filename:
git reset HEAD <filename>
@(a shortcut for
HEADsince Git v1.8.5) with the filename:
git reset @ <filename>
<filename> with the actual name of the file you want to unstage.
Understanding the Impact
git reset command in this way only affects the staging area and doesn't change the contents of your files. It's a safe way to undo the staging before you commit, allowing you to review and reselect the files for your commit.
HEAD is a reference to the last commit of the current branch. When you use
git reset, you’re essentially telling Git to make the staging area look like the last commit (
HEAD), without altering the working directory.