World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Take it out of the box

You will learn: how to take a file out of the box without losing your work.

The problem

Two files wobble in the box: index.html with a green tick, and style.css marked not ready.

You typed git add . too fast. A half-done file jumped into the box. How do you get it out?

Watch

The command git restore --staged style.css types itself. style.css slides out of the box, back to the working folder. index.html stays in the box.

git restore --staged style.css takes the file out of the box. This is called unstaging.

Try it

Drag the half-done file back out of the box.

Tap a file, then tap a box. Or drag it.

  • Drop here

Try it

Now type the command yourself.

Working folder
  • Empty
Staging area
Repository
  • 3 save points
  • Add style
  • Add day 1 page
  • Add README

Predict

You just unstaged style.css. Where are your edits now?

Pick one answer.

Check

git status lists index.html and style.css in the box. A hint line says: use git restore --staged to unstage. Terminal output: $ git status On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: index.html modified: style.css

Forgot the command? git status tells you. Look for the hint that says “to unstage”.

You did it!

You can now take a file out of the box, safely.

Go deeper (optional)

git reset style.css does the same thing. It is the older way. git restore --staged . empties the whole box.

git reset style.css also takes style.css out of the box. Its edits stay in the folder. Terminal output: $ git reset style.css Unstaged changes after reset: M style.css $ git status -s M index.html M style.css