If you have added files to a staging area by running git add
command and now want to undo git add operation, then all you have to do is run git reset
command.
Lat's say you have added sales.csv file.
$git add sales.csv $git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) modified: sales.csv
You can see that sales.csv
file is in a staging area.
To undo git add operation, run the below command:
$git reset HEAD sales.csv
After running git reset
command, you will find that file is in the modified state.
$git status On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: sales.csv no changes added to commit (use "git add" and/or "git commit -a")
Here, you can see that sales.csv file is in a modified state.
If you want to undo the changes made to a file, then run git checkout
command.
$git checkout -- sales.csv
The below images explains the entire process of undoing git add operation.