ShellProven
Lesson 03 · tested on Debian 13

Undo anything in Git: restore vs reset vs revert (live demos)

Five real "undo" situations in Git, each shown live: throw away an edit with git restore, unstage a file with git restore --staged, undo the last commit but keep the changes with git reset --soft, drop a commit with git reset --hard and get it back with git reflog, and safely undo a commit that's already shared with git revert.

Video coming soon — @ShellProven

Commands

Exactly as run in the video. Full folder with setup script and log: terminal-tutorials/git-undo.

# The demo repository
$ git log --oneline
f1f7a48 Enable debug
b01e5d3 Add currency
52e0461 Add config

# 1. Throw away an edit: git restore
$ echo "price = 0" >> app.conf
$ git status --short
 M app.conf
$ git restore app.conf
$ cat app.conf
price = 10
currency = EUR
debug = true

# 2. Unstage a file: git restore --staged
$ echo "tax = 23" >> app.conf && git add app.conf && git status --short
M  app.conf
$ git restore --staged app.conf && git status --short
 M app.conf
$ git restore app.conf

# 3. Undo the last commit, keep the changes: reset --soft
$ git reset --soft HEAD~1
$ git status --short && git log --oneline
M  app.conf
b01e5d3 Add currency
52e0461 Add config
$ git commit -qm "Enable debug (only in dev)" && git log --oneline
4949205 Enable debug (only in dev)
b01e5d3 Add currency
52e0461 Add config

# 4. Drop a commit with reset --hard, then get it back
$ git reset --hard HEAD~1
HEAD is now at b01e5d3 Add currency
$ cat app.conf
price = 10
currency = EUR
$ git reflog | head -3
b01e5d3 HEAD@{0}: reset: moving to HEAD~1
4949205 HEAD@{1}: commit: Enable debug (only in dev)
b01e5d3 HEAD@{2}: reset: moving to HEAD~1
$ git reset --hard "HEAD@{1}" && git log --oneline
HEAD is now at 4949205 Enable debug (only in dev)
4949205 Enable debug (only in dev)
b01e5d3 Add currency
52e0461 Add config

# 5. Undo a shared commit: git revert
$ git revert --no-edit HEAD
[main e8bee19] Revert "Enable debug (only in dev)"
 Date: Sat Nov 21 19:07:10 2026 +0000
 1 file changed, 1 deletion(-)
$ git log --oneline && cat app.conf
e8bee19 Revert "Enable debug (only in dev)"
4949205 Enable debug (only in dev)
b01e5d3 Add currency
52e0461 Add config
price = 10
currency = EUR

Quick check

Same two questions as in the video. Checked here, in your browser — nothing is sent anywhere.

Transparency. Script and narration made with AI, human-reviewed. The robot and the dog are AI-generated cartoon characters. The commands and their output are real runs in a container.