CodeBlanks Logo Icon CodeBlanks

Summary - Reset

Combine reset modes to clean local changes.

Reset modes and usage strategy

git reset is the most powerful tool for managing commits and staging during local development. Choose --soft to fix commit message or scope, --mixed to unstage while preserving files, and --hard to discard everything. The HEAD~n reference easily specifies how many commits to step back.

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

Which mode you choose depends on whether you want changes kept in stage, kept in working directory, or discarded entirely.

Practice Clear stage with mixed reset and verify

Undo the latest commit with git reset --mixed -q HEAD~1, print file content with cat rapor.txt, and print status with git status -s.

Starter code

terminal
git init -q -b main
git config user.name "Gamze"
git config user.email "gamze@example.com"
echo "stabil surum" > rapor.txt
git add rapor.txt
git commit -qm "Stabil"
echo "taslak notlar" > rapor.txt
git commit -am -q "Taslak commit"

# mixed reset at, dosya icerigini ve durumunu bas

Sample solution

terminal
git init -q -b main
git config user.name "Gamze"
git config user.email "gamze@example.com"
echo "stabil surum" > rapor.txt
git add rapor.txt
git commit -qm "Stabil"
echo "taslak notlar" > rapor.txt
git commit -am -q "Taslak commit"

git reset --mixed -q HEAD~1
cat rapor.txt
git status -s

Expected output

taslak notlar
 M rapor.txt

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What command should someone use to change the message of the latest commit or add a new file to stage and recreate the commit?

  • git revert --no-edit HEAD
  • git reset --hard HEAD~1
  • git stash clear
  • git reset --soft HEAD~1 Correct answer

Explanation: git reset --soft HEAD~1 undoes the latest commit while keeping changes staged; allowing you to add more files and recommit as a single commit.

2 Clear stage with default mixed reset

Question
git reset ____ HEAD~1
Answer
git reset --mixed HEAD~1

Explanation: The --mixed mode moves HEAD backward and clears the stage while preserving changes in the working directory.

3 Reset strategies

Term Meaning
Soft reset Keeps changes in staging area
Mixed reset Keeps changes in working directory
Hard reset Rolls back entire working tree
HEAD~ referansı Specifies number of steps backwards

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow