GitInterview preparation
Foundation·Concept·2 min read

Reset vs revert, and when should I use stash?

Practice this question

Definition:

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.

Key points:

  • 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.

Interview point:

  • For an already shared bad commit, revert is usually easier for a team to follow because it adds history instead of rewriting it.
Adapted from 09_TESTING_GIT_DOCKER_CLOUD.md · “Reset vs revert, and when should I use stash?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.