Unstage a file

Description: You staged secret.txt by mistake. Remove it from the staging area, but keep the file.

Hint:

  • Use git restore --staged.

Solution

Terminal output

$ git status -s
A secret.txt
$ git restore –staged secret.txt
$ git status -s
?? secret.txt
$ ls
app.txt
secret.txt

How it works

  • A (staged) changes to ?? (untracked), and the file stays in the folder.
  • Add the file to .gitignore so this does not happen again.

Read Git Restore.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.