Lesson02
beginnerDiscard and Unstage with git restore
Goal
Throw away an edit you do not want, and take a file back out of the staging area.
Two things went wrong. An experiment broke index.html, and you want the committed version back. And notes.md, your private to-do list, got staged by accident: it should stay in your working tree, just not in the next commit.
Objectives
0/3notes.mdis no longer staged. (Current objective)notes.mdis still in your working tree. (Not started)index.htmlis back to its committed version. (Not started)
Your task nowStep 1 of 3
notes.md is no longer staged.
Need help?
Reference
Two kinds of restore
git restore <file>
- Copies the staged version back over the file
- Throws away unstaged edits for good
git restore --staged <file>
- Copies the committed version into the staging area
- Unstages the file; your edits stay in the working tree
Unstaging keeps your work
Step 1 of 2
Working Tree
Empty
Staging Area
- notes.mdStaged
Repository
- index.html
notes.md is staged by mistake.
Step 1 of 2. `notes.md` is staged by mistake.
Preparing your workspace…
Repository Graph
Click a commit to inspect it
Working Tree
Not a Git repository yet
No unstaged changes
Your working tree matches the staging area.
Staging Area
Files prepared for the next commit
No staged changes
Use git add to prepare files for your next commit.
Repository
Committed history
No commits yet
Use git commit to record staged changes.
