Course contentsShow
← Git & GitHub
Lesson 29 of 962. Core Git MechanicsFree lesson

Resetting Commits with Soft and Mixed Modes

Understand how to move the branch pointer backward while choosing whether to preserve changes in the staging area or directory.

In this lesson, you will learn how to move your branch pointer backward in history while choosing whether to keep your recent work safely staged or ready for further editing.

Sometimes you make a commit only to realize you forgot a file, made a typo in the message, or just want to redo the snapshot. Git allows you to "undo" commits by moving your branch pointer to a previous state using the git reset command. The mode you choose determines what happens to the files you were working on.

The Soft Reset (--soft)

When you use git reset --soft HEAD~1, Git moves the branch pointer back one commit. Crucially, the changes from that "undone" commit are kept in your staging area.

This is perfect if you want to keep your work but bundle it differently or refine the commit message. Your files remain staged and ready to be committed again immediately.

The Mixed Reset (--mixed)

This is the default mode if you don't specify a flag (git reset HEAD~1). Like the soft reset, it moves the branch pointer backward. However, it unstages all your changes. The files remain in your working directory, but they are returned to an "unstaged" state.

Think of the difference like this:

  • Soft: "I want to undo the commit, but keep everything exactly how it was ready for the next commit."
  • Mixed: "I want to undo the commit, but I want to rethink which files belong in the staging area."

Illustrative Example

Imagine you just committed a set of changes, but you realized you included a file you didn't mean to.

  1. Soft Reset: git reset --soft HEAD~1
    • Your changes remain staged. You can now unstage the unwanted file and commit the rest.
  2. Mixed Reset: git reset --mixed HEAD~1
    • Your changes move to the working directory. You now see them as unstaged, allowing you to carefully pick which specific files you want to re-stage.

Both methods leave your actual project files intact, ensuring no code is ever lost—only the record of the commit itself is shifted.

Key Takeaway: Use --soft when you want to keep your changes staged for a quick re-commit, and use --mixed when you want to revert to an unstaged state to review or adjust your work.