How to use the Git command git reset

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Table of contents

The git reset command is a powerful Git tool used to undo changes in your repository. It modifies your current branch history, and depending on the mode, it can also affect your staging area and working directory.

Graphite users will find git reset especially useful when cleaning up commits before publishing or when rewriting history in preparation for a stacked PR workflow.

Terminal
git reset [<mode>] [<commit>]
  • <mode> can be --soft, --mixed (default), or --hard.
  • <commit> specifies the commit hash, branch, or reference you want to reset to.
  • Moves the branch pointer to the target commit.
  • Leaves staging area and working directory intact.
  • Useful when you want to re-stage and amend commits.
Terminal
git reset --soft HEAD~1

This resets the branch one commit back but keeps changes staged.

  • Moves the branch pointer.
  • Clears the staging area (unstages changes).
  • Leaves the working directory intact.
Terminal
git reset HEAD~1

This keeps file modifications but unstages them.

  • Moves the branch pointer.
  • Clears the staging area.
  • Discards changes in the working directory.
Terminal
git reset --hard HEAD~1

This completely removes the last commit and all associated changes.

Caution: This is destructive. Use with care, especially on shared branches.

Graphite’s workflow encourages clean commit stacks for easier code review.

  • Use git reset --soft if you need to squash or edit a commit before publishing a stack.
  • Use git reset --mixed when you want to reorganize commits without losing your actual code changes.
  • Avoid --hard resets unless you are confident no work will be lost.

When collaborating with Graphite, always reset only local, unpublished commits. If commits are already stacked and pushed, prefer git revert to avoid rewriting public history.

  • git reset rewrites history, moving the branch pointer backward.
  • git revert creates a new commit that undoes a previous one, preserving history.
  • In Graphite, prefer revert for published stacks to avoid conflicts.
  • Use --soft if you want to re-stage and adjust commits.
  • Use --hard only when you're certain you don't need the changes anymore.
  • Sometimes, yes. You can use git reflog to find the discarded commit hash and reset back to it.
  • But don't rely on this as a safety net—proceed carefully.
  • In Graphite's stacked workflow, resets are safe for local (unpushed) commits.
  • For published stacks, use amend or revert instead to avoid disrupting reviewers.
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone