Restoring and Unstaging Files
Modern Git provides git restore for restoring working-tree files and removing changes from the staging area. git restore file.js discards unstaged modifications to that file, while git restore --staged file.js removes it from the staging area without discarding its working-tree changes.
git restore file.js can permanently discard uncommitted modifications to that file. Inspect the diff first if the changes matter.
git restore app.js
git restore --staged app.js
git restore --source=HEAD~1 app.jsThe first command restores the working file from the index. The second removes it from staging. The third restores the file from another commit.
git restore --stagedunstages without discarding the working copy.git restorecan discard working-tree changes.Use explicit source commits when restoring historical versions.
What does git restore --staged file.js do?