Git Reset Soft

What

The git reset --soft command allows you to roll back your repository’s commit history to a specific past commit while keeping all the file modifications you made after that point intact and staged in your staging area.

How

Specify the commit hash you want to roll back to:

# Undo the latest commit(s) but keep all changes staged in the index
git reset --soft <target_commit_hash>

For example, if your history has commits A - B - C (where C is the latest commit), running git reset --soft B will:

  • Move the active branch pointer back to B.
  • Delete commit C from the timeline.
  • Keep the modifications made in commit C in your staging area, ready to be recommitted.

Why

git reset --soft is the ideal tool when you need to restructure your history or revise commit messages. If you commit changes prematurely or realize you want to combine several small commits into one large, cohesive commit, you can use a soft reset to “uncommit” the code, adjust your modifications, and write a new, cleaner commit message.

Summary

Use git reset --soft <commit_hash> to revert your active branch pointer to a past commit without losing any of your modified file changes, leaving them staged for a new commit.