Git & GitHub Interview Question #51

What are the main modes of git reset?

Undo & Recovery, Tags, Forks, Pull Requests & Code Review Mid-Level Intermediate

Quick Interview Answer

git reset can move the current branch reference and optionally update the staging area and working tree. The three commonly discussed modes are --soft, --mixed, and --hard.

Detailed Explanation

git reset can move the current branch reference and optionally update the staging area and working tree. The three commonly discussed modes are --soft, --mixed, and --hard.

--soft moves HEAD while keeping changes staged. --mixed, the usual default, moves HEAD and resets the index while keeping working-tree changes. --hard also resets the working tree and can permanently discard uncommitted changes, so it must be used carefully.

Code Example

git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1