Menu
Coddy logo textTech

Discard Unstaged Changes

Part of the Version Control section of Coddy's Terminal journey — lesson 40 of 58.

Sometimes you make edits in the working directory that you regret and want to throw away. As long as the changes have not been staged, you can roll the file back to its committed version with:

git restore notes.txt

This overwrites your working copy of notes.txt with the version from the latest commit. You lose your unsaved edits, but the staging area and history are unchanged.

If you want to throw away every unstaged change in the repo at once, use a dot:

git restore .

git restore is destructive: anything you have not committed (or staged) is gone after this. Use it deliberately.

challenge icon

Challenge

Beginner

The folder contains config.txt with the line port=80, already committed. Modify it to port=9999, then immediately discard the change with git restore. Print the final contents of the file.

Cheat sheet

Discard unstaged changes in a specific file (reverts to last commit):

git restore notes.txt

Discard all unstaged changes in the repo at once:

git restore .

Warning: git restore is destructive — uncommitted and unstaged changes are permanently lost.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control