init: git reset
In this video we'll learn how to use git reset
.
There will be times you add or remove the wrong change.
To unstage these changes, we can use git reset
.
In fact, you may have noticed this suggestion when running git status
.
Let's demonstrate this by quickly creating and adding a new file.
We'll run git status
to verify the file was staged.
We also notice the suggestion for using git reset
to unstage this file.
We'll streamline the suggested command by dropping HEAD
as this is the default. we'll learn how to use HEAD
later.
Let's run:
git reset new-file.txt
When we run git status
we see the new file has gone back to being untracked.
So git reset
effectively undid our git add
command.
We can also run git reset
without passing the file argument. This will reset all staged changes.
So, in its basic usage, we can use git reset
to undo the commands like git add
and git rm
.