Junior — Middle
Can you explain the differences between the git reset commands with the --soft, --mixed, and --hard options?
sobes.tech AI
Answer from AI
The git reset command is used to move the branch pointer and change the state of the index and working directory. The differences between parameters:
-
--soft— moves the branch pointer (HEAD) to the specified commit, leaving the index and working directory unchanged. Changes remain in the index as if prepared for commit. -
--mixed(default) — moves the branch pointer and resets the index to the specified commit, but does not change the working directory. Changes become unstaged. -
--hard— moves the branch pointer, resets the index and working directory to the specified commit. All uncommitted changes will be lost.
Example:
# Move HEAD to the previous commit, keep changes in index
git reset --soft HEAD~1
# Move HEAD to the previous commit, reset index, keep changes in working directory
git reset --mixed HEAD~1
# Move HEAD to the previous commit, reset index and working directory
git reset --hard HEAD~1