Moving Back with Reset
Git reset.
Git reset moves your branch back to an earlier commit, as if the later commits never happened. It's great for cleaning up work you haven't shared yet. It has three modes, soft, mixed, and hard.

- Moves your branch back
- Later commits disappear from the log
- Three modes: soft, mixed, hard
Soft and mixed
Here, reset dash dash soft, head tilde one, which means one commit before head. The banner commit is gone from the log, but its change is still staged, ready to commit again. Now a plain reset, which is called mixed. Same thing, but the change is unstaged, sitting in your working folder.
git reset --soft HEAD~1 git log --oneline -n 2 f63a17a (HEAD -> main) Link to about page ef9c947 Add basic styles git status --short M index.html git reset Unstaged changes after reset: M index.html git status --short M index.html
Hard
And now dash dash hard. This moves back, and throws the changes away completely. The log no longer has the banner commit. And status is clean. The banner is gone from the files too.
git reset --hard HEAD~1 HEAD is now at f63a17a Link to about page git log --oneline -n 2 f63a17a (HEAD -> main) Link to about page ef9c947 Add basic styles git status On branch main nothing to commit, working tree clean
The three modes
Here are the three modes side by side. All of them move the branch back. Soft keeps the changes staged. Mixed, the default, keeps them in your files, unstaged. Hard throws them away. Use hard carefully.
| Mode | Commit | Changes |
|---|---|---|
| --soft | removed | kept, staged |
| --mixed (default) | removed | kept, unstaged |
| --hard | removed | thrown away |
Summary
git reset moves your branch back. Soft keeps changes staged, mixed keeps them unstaged, hard throws them away. Next, when to use reset, and when to use revert.
Key takeaways- --soft: staged
- --mixed: unstaged
- --hard: gone