Rewinding with git reset
git reset moves your branch back to an earlier commit. It has three modes, which differ in what happens to your changes:
--soft: undo the commit, keep the changes staged.- (default)
--mixed: undo the commit, keep the changes but unstaged. --hard: undo the commit and throw the changes away.
HEAD~1 means "one commit before the current one".
The commit "Three" is gone from the log, but its change is still staged. Recommit it, then try the default mode, which unstages the change.
Finally --hard, the dangerous one. It rewinds the files too, so the work in them is lost.
git reset is safe for commits you have not pushed. Never use it to rewrite commits other people already have.
Which command undoes the last commit and throws its changes away?
Make two commits, then throw the last one away with a hard reset, and print how many commits remain.
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.