Both [`git reset`](/git/commands/git-reset) and `git revert` let you undo changes, but they work in fundamentally different ways. Choosing the wrong one on a shared branch can cause problems for everyone on your team.

## git reset — rewrite history

`git reset` moves the branch pointer backwards, effectively removing commits from the history.

```bash
# Remove the last commit; keep the changes staged
git reset --soft HEAD~1

# Remove the last commit; keep changes unstaged
git reset HEAD~1

# Remove the last commit; discard the changes entirely
git reset --hard HEAD~1
```

Because `reset` changes history, it creates a conflict for anyone else who already has those commits. If you push after a `reset`, you will need to force-push.

For a practical walkthrough, see [how to undo your last commit](/git/faqs/undo-last-git-commit).

## git revert — create an undo commit

`git revert` creates a new commit that applies the inverse of a previous commit. The original commit stays in the history.

```bash
# Revert the most recent commit
git revert HEAD

# Revert a specific commit by hash
git revert a1b2c3d
```

Git opens your editor to confirm the commit message. You can push the result normally — no force-push needed. For a step-by-step example, see [how to revert to a previous commit](/git/faqs/revert-git-repository-previous-commit).

## Comparison at a glance

| | `git reset` | `git revert` |
|-|-------------|-------------|
| How it works | Moves the branch pointer back | Creates a new undo commit |
| History | Rewritten | Preserved |
| Safe for shared branches? | No | Yes |
| Requires force-push? | Yes (if already pushed) | No |

## When to use each

Use **`git reset`** when the commits are local and have not been pushed.

Use **`git revert`** when the commits are already on a shared or remote branch, or when you want a clear audit trail showing that a change was reversed.

You can use [`git log`](/git/viewing-previous-commits) to review the commit history before deciding which approach to take.

Ready to streamline your Git workflow? [DeployHQ](https://www.deployhq.com) deploys your code automatically whenever you push to your repository.