Sobes.tech
Junior — Middle

Can you explain what the git reset command does and in what scenarios it is used?

sobes.tech AI

Answer from AI

The git reset command is used to undo changes and move the current branch pointer (HEAD) to another commit. It can modify the state of the index (staging area) and the working directory depending on the options.

Main options:

  • git reset --soft <commit> — moves HEAD to the specified commit, leaving changes in the index and working directory. Used to undo commits but keep changes for recommitting.

  • git reset --mixed <commit> (default) — moves HEAD and resets the index, but changes remain in the working directory. Allows undoing commits and removing changes from the index.

  • git reset --hard <commit> — moves HEAD, resets the index and working directory, completely removing all changes after the specified commit.

Use cases:

  • Undo recent commits.
  • Remove changes from the index.
  • Full rollback to a previous state.

Example:

git reset --hard HEAD~1  # rollback one commit back with changes removed
Can you explain what the git reset command does and… - sobes.tech