How to remove a file (git undo add) from staging ready for the next commit?

Upon completion of a feature as a part of bigger software development, the next step is to commit the changes done.  The changes may include modified as well as new files.  To list all types you can use the git status command.

Next is to add source files for the next commit using the git add command. You may select files individually to add or can add all files using an all option with the command. Now time to use the commit command to commit all changes in the local repository copy.

But just before entering the commit command, you noticed that there are one or more files that are not needed, may require more code changes or you have added them accidentally.  The reasons can be any. But you need to remove the undesired files or undo stagged them from the next commit.

How to remove the added files? Would you need to start again or do I have something like undo git add? In this tutorial for git, you will learn how to undo an already executed git add command.

The reversing is called git undo add or git unadd. For that, there is a git reset command.   The git reset can be used to undo a specific added file or to undo all staged files.

Git Reset command example for undo a git add?

  • #git reset <filename>   (to undo a add for a file)
  • #git reset ( for all files)