shellstreak

Unstage a file (undo git add)

Safe: nothing is lost

Short answer

Run git restore --staged <file>. The file leaves the staging area, and your edits stay in the file.

The commands, one by one

  1. 1git restore --staged notes.txt

    Takes notes.txt out of the next commit. Its content on disk doesn't change.

  2. 2git status -s

    The file now shows M in the second column: changed, not staged.

For your own repository: Use your own file name. git restore --staged . unstages everything.

Try it safely

You staged bread.txt and notes.txt, but notes.txt isn't ready.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 28, Undo changes, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.