Reset vs revert, and when should I use stash?
Understand the concept
Reset changes the current branch reference and may also change staged or working files depending on its mode. Revert records a new inverse change while preserving shared history. Stash stores local changes temporarily so another operation can proceed, but it should not replace committing important work.
Important ideas
-
Reset moves the branch pointer; some modes also change staged or working files.
-
Revert adds a new commit that undoes earlier changes; useful on shared branches.
-
Stash temporarily stores local work; include untracked files explicitly when needed.
-
reset --hardcan discard tracked local changes; understand the mode before using it.
Comparison:
| Tool | Changes history how? | Typical use |
|---|---|---|
| Reset | Moves the current branch reference | Adjust local commits or staging |
| Revert | Adds an undo commit | Undo a shared change safely |
| Stash | Temporarily stores local work | Switch tasks before a commit |
- Check the working tree first; reset modes differ, and hard reset can discard local tracked changes.
Can you explain it without the notes?
Reset vs revert, and when should I use stash?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Reset changes the current branch reference and may also change staged or working files depending on its mode. Revert records a new inverse change while preserving shared history. Stash stores local changes temporarily so another operation can proceed, but it should not replace committing important work.
Turn this concept into a clear answer.
- For an already shared bad commit, revert is usually easier for a team to follow because it adds history instead of rewriting it.
Keep connecting the ideas.
Next lesson: How do I resolve a merge conflict or find a bad commit?Adapted from 09_TESTING_GIT_DOCKER_CLOUD.md · “Reset vs revert, and when should I use stash?”. Examples are study fragments; framework behavior can depend on your version.