Lesson04
intermediateUndo Commits with git reset
Goal
Take back a commit you just made, keep its changes, and commit them properly.
You committed in a hurry: the last commit is called WIP and contains your login form together with a stray debug.log. Nobody else has seen it yet, so you can rewrite it.
Undo the commit while keeping its changes, then commit the login form on its own, with a real message.
Objectives
0/4- The
WIPcommit is no longer onmain. (Current objective) - The login form is still in your working tree. (Not started)
mainhas a commitAdd login form. (Not started)debug.logis not part of any commit onmain. (Not started)
Your task nowStep 1 of 4
The WIP commit is no longer on main.
Need help?
Reference
Undo the last commit, keep the changes
$ git reset HEAD~1
Unstaged changes after reset: M src/app.js
HEAD~1 means "one commit before HEAD". The branch moves back there; the undone commit's changes stay in your files as unstaged edits (new files become untracked again).
The same, but keep them staged
$ git reset --soft HEAD~1
Nothing is printed. The changes are still staged, ready to commit again.
Preparing your workspace…
Repository Graph
Click a commit to inspect it
Working Tree
Not a Git repository yet
No unstaged changes
Your working tree matches the staging area.
Staging Area
Files prepared for the next commit
No staged changes
Use git add to prepare files for your next commit.
Repository
Committed history
No commits yet
Use git commit to record staged changes.
