LESSON 02 / 3·2 min readFoundation

Reset vs revert, and when should I use stash?

01 Understand02 Recall03 Prepare

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 --hard can discard tracked local changes; understand the mode before using it.

Comparison:

ToolChanges history how?Typical use
ResetMoves the current branch referenceAdjust local commits or staging
RevertAdds an undo commitUndo a shared change safely
StashTemporarily stores local workSwitch tasks before a commit
  • Check the working tree first; reset modes differ, and hard reset can discard local tracked changes.
PAUSE & RECALL

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.

CONNECT IT TO YOUR INTERVIEW

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.
Practice this concept
YOUR NEXT STEP

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.