Sometimes we mistakenly add some files using git add command before we do commit. In order to undo git add before commit follow the below commands.
You can undo git add before commit using:
git reset <file_name>
Suppose you have added a file named file1.txt using git add command mistakenly, to undo it use:
git reset file1.txt
The above command will remove the file from the current index (Staging area) without doing anything else.
If you have added many files and want to remove all of them at once then use:
If you are using older versions of Git then it’s mandatory to use HEAD in the git reset command. Look at the below example.
git reset HEAD file_name.txt
Also Read :