Let's learn how to undo changes that have been staged
Make changes to the hello.html
file in the form of an unwanted comment
<html>
<head>
<!-- This is an unwanted but staged comment -->
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Stage the modified file.
RUN:
git add hello.html
Check the status of unwanted changes .
RUN:
git status
RESULT:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.html
#
Status shows that the change has been staged and is ready to commit.
Fortunately, the displayed status shows us exactly what we should do to cancel staged changes.
RUN:
git reset HEAD hello.html
RESULT:
$ git reset HEAD hello.html
Unstaged changes after reset:
M hello.html
The reset
command resets the buffer zone to HEAD. This clears the buffer zone from the changes that we have just staged.
The reset
command (default) does not change the working directory. Therefore, the working directory still contains unwanted comments. We can use the checkout command from the previous tutorial to remove unwanted changes from working directory.
RUN:
git checkout hello.html
git status
RESULT:
$ git status
# On branch master
nothing to commit (working directory clean)
Our working directory is clean again.