Undo the Last Commit
Reset moves the branch pointer back. It undoes the last snapshot while keeping the changes somewhere safe.
Undo the snapshot, keep the changes staged
Reset prints nothing. Status shows the change back on the staging list.
$ git reset --soft HEAD~1
$ git statusSee the shorter log
The coffee snapshot is gone from the log. The tea snapshot is newest now.
$ git log --onelineUnstage the changes too
Plain reset moves the pointer and unstages. The change stays in the file.
$ git reset HEAD
$ git statusExample
$ git reset --soft HEAD~1
$ git log --onelineKey points
- Reset with --soft moves the pointer and keeps the changes staged.
- The snapshot is gone from the log. The changes wait on the staging list.
- Reset with no words moves the pointer and unstages the changes.
- HEAD~1 means one snapshot before the newest one.
- Reset only moves the pointer. Older snapshots stay in the history.
- Use reset for your own recent mistakes, never for shared work.
Here, reset moves the pointer back one snapshot. The coffee snapshot leaves the log, and the tea snapshot is newest again.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does git reset --soft HEAD~1 keep?