git undo add
Table of contents
Git does not automatically include changes in a commit: they have to be explicitly added to the next commit, with the git add command.
But sometimes you might change your mind and decide that a certain file should not be part of the next commit. In this short article, we’ll answer the question of how to undo adding a change to the staging area, after having used git add before.
Luckily, there’s a simple way of undoing a git add: you can simply use the git restore --staged command on the affected file:
$ git restore --staged index.html
This will remove the file from Git’s staging area, making sure it is NOT part of the next commit.
If, at the same time, you also want to discard any local changes in this file, you can simply omit the --staged flag:
$ git restore index.html
This will undo any modifications in this file since you last committed it. Please be careful with this command: undoing uncommitted local changes cannot be undone!