Remove Files from the Staging Area
You are working on a project in the git-playground
repository. You have made some changes to the files and added them to the staging area using the git add
command. However, you realize that you accidentally added a file that you don't want to commit. You need to remove this file from the staging area.
- View current working directory status:
git status
- Remove the
newfile.txt
file from the staging area using the git restore --staged
command:
git restore --staged newfile.txt
- Verify that the file has been removed from the staging area using the
git status
command:
git status
This is the final result:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
newfile.txt