← Git from Scratch
Lesson 6 of 17 · 10 XP
git diff and git restore: see and undo
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
git diff shows exactly what changed in the working directory compared to the last commit:
--- a/config.txt
+++ b/config.txt
port=8000
-debug=false
+debug=true
Lines with - were removed, lines with + were added.
If the edits went wrong and need to be thrown away, return the file to its state in the last commit:
git restore config.txt # WARNING: uncommitted edits in the file are lost for good
This is one of the few git commands that truly deletes your work. Git keeps everything that was committed safe, but what was never committed can't be recovered.
More useful commands:
git diff --staged # what's already in the index
git restore --staged file # remove from the index, keep the edits
Task. Someone has messed up config.txt in the working directory. Look at the changes with git diff, and then return the file to its last committed state.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.