There might be cases when you added files (temporary, libraries, executes, etc.) by executing for example git add --all
. Before or during the commit you notice that they shall not be included in the git repository. In this post I demonstrates how to remove/undo/unstage files added/staged accidentally.
Unstage a single file
Let’s say test.cpp~
was added by accident and you would like to undo the add. This can be done as follows:
git reset test.cpp~
Unstage multiple files
If you need to remove multiple files, wildcards
can be used, for example:
git reset *.cpp~
Unstage all the added/staged files
If you need to undo all the added files you can use git reset
without additional inputs.
git reset
Demonstration
The video below demonstrates the described git commands above: