Restore (staged)

Restore (staged)

We can do the same even if the file was staged for commit (we may not use this in real world) as shown in the below steps-

Before trying this out you might want to modify the file again and add it for staging and then check the status

git add .

PS C:\Users\ravi_\Source\repos\Experiments\GitExperiments\FirstDemo> git status
On branch master

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   hello.txt
 git restore . --staged
git status

On branch master

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

Notice that the latest status shows the file as not staged for commit because we just unstaged it if you want to unmodified it as well, we can issue git restore . command at this point!

A reload might be required in the text editor to reflect the changes which Git is doing!

Last updated