Un-staging files

Suppose that we've added some changes to the staging area, but we now realize that we shouldn't have. We want to un-stage our file(s) and get it back to the working area. To solve this we run

git restore --staged file_name.ext
Un-staging files 1

We can pass one filename, multiple files separated by a space, patterns such as *.txt, or a period to indicate all files. This tells Git to take the changes that are already in the staging area and revert them to the working directory. What Git is doing here under the hood is taking the last version of our file from the next environment. So, if we restore a file that is in the staging area, the last version from the next environment is the state of the file in the last commit. Git will take this version and place it in the staging area.

Un-staging files 2

Now suppose the file we want to restore is a new file, so it didn't exist at the last commit. If we restore this file, Git will take the staging area version of it, and place it in the working directory as a new un-tracked file.