git restore
The command that throws away uncommitted changes to a file, or with --staged takes a file back out of the staging area.
Without --staged it discards uncommitted edits that Git has no copy of.
In more detail
git restore notes.txt copies the staged version back over the working tree file, discarding your edit with no way to recover it. git restore --staged notes.txt resets the staging area copy to the last commit and leaves your edit on disk. It was added in Git 2.23 to take over those jobs from git checkout.
Example
git restore --staged recipes.mdRelated terms
- staging area — Git's list of exactly what the next commit will contain, kept in the file .git/index; also called the index.
- working tree — The files of a Git repository as they currently exist on disk, which you edit before staging and committing.
- git reset — The command that moves the current branch to another commit, and depending on the mode also resets the staging area and working tree.
- --staged — A flag that points a command at the staging area instead of the working tree, as in git diff --staged or git restore --staged.
Taught in
- The Three Areas: Working Tree, Index, Repository — Advanced Git Internals & Distributed Workflows
- Staging Deliberately: status, add, add --patch — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- Undoing: restore, reset, revert And stash — Advanced Git Internals & Distributed Workflows