ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://sentry.io/answers/revert-a-git-repository-to-a-previous-commit/ |
| Last Crawled | 2026-04-18 01:27:24 (5 hours ago) |
| First Indexed | 2023-06-21 06:47:38 (2 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Revert a Git repository to a previous commit | Sentry |
| Meta Description | Sentry helps developers monitor and fix crashes in real time. Get the details you need to resolve the most important issues quickly. |
| Meta Canonical | null |
| Boilerpipe Text | The Problem
How do I revert a Git repository to a previous commit?
The Solution
In Git, the word “revert” has a special meaning. You can use the
git revert
command to return your repository’s files to a previous state without rewriting the commit history. This is done by creating new commits that do the opposite of existing commits, i.e. removing lines and files that were added and adding lines and files that were removed.
To revert the most recently created commit, you can specify its hash or use
HEAD
:
git
add
.
git
commit
-m
"This commit is a mistake"
git
revert HEAD
# will create a new commit doing the opposite of the one above
To revert multiple recent commits, you can specify a range, from oldest to newest. One new commit will be created for each reverted commit.
git
revert HEAD~3
..
.HEAD
# revert the last three commits
git revert
is a good way to restore a previous state while retaining the repository’s edit history. However, in some cases, you may prefer to delete previous commits rather than reverse them. To do this, you can use
git reset --hard
, specifying the commit to return to:
git
reset
--hard
HEAD~
This will return the repository’s files to their previous state and remove the most recent commit from the current branch’s history. For more on
git reset
, take a look at our answer for
undoing Git commits
.
Further Reading
If you’re looking to get a deeper understanding of how application performance monitoring works, take a look at the following articles:
Releases Are Better With Commits
Improve Your Workflow with Sentry
11 Habits of Highly Effective Developers |
| Markdown | [Skip to main content](https://sentry.io/answers/revert-a-git-repository-to-a-previous-commit/#main-content)
Menu
Platform
Products
- [Error Monitoring](https://sentry.io/product/error-monitoring/)
- [Logs](https://sentry.io/product/logs/)
- [Session Replay](https://sentry.io/product/session-replay/)
- [Tracing](https://sentry.io/product/tracing/)
- [Seer NEW](https://sentry.io/product/seer/)
- [Profiling](https://sentry.io/product/profiling/)
- [AI Code Review NEW](https://sentry.io/product/seer/ai-code-review/)
- [Size Analysis NEW](https://sentry.io/product/size-analysis/)
- [Cron Monitoring](https://sentry.io/product/cron-monitoring/)
- [Uptime Monitoring](https://sentry.io/product/uptime-monitoring/)
- [Sentry CLI NEW](https://cli.sentry.dev/)
Integrations
- [Github](https://sentry.io/integrations/github/)
- [Slack](https://sentry.io/integrations/slack/)
- [Sentry MCP NEW](https://mcp.sentry.dev/)
- [All Integrations](https://sentry.io/integrations/)
SDKs
- [Javascript](https://sentry.io/for/javascript/)
- [Python](https://sentry.io/for/python/)
- [React](https://sentry.io/for/react/)
- [Laravel](https://sentry.io/for/laravel/)
- [Next.js](https://sentry.io/for/nextjs/)
- [All SDKs](https://sentry.io/platforms/)
Solutions
### Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
Resources
Learn
- [Blog](https://blog.sentry.io/)
- [Changelog](https://sentry.io/changelog/)
- [Sandbox](https://sandbox.sentry.io/)
- [Resources](https://sentry.io/resources/)
- [Syntax](https://syntax.fm/)
- [Customers](https://sentry.io/customers/)
- [Cookbook](https://sentry.io/cookbook/)
Support
- [Contact Us](https://sentry.io/contact/enterprise/)
- [Help Center](https://help.sentry.io/)
- [Status](https://status.sentry.io/)
Hang out with us
- [Sentry Build](https://sentry.io/resources/sentry-build/)
- [Events](https://sentry.io/events/)
- [Merch](https://sentry.shop/)
[Docs](https://docs.sentry.io/)
[Pricing](https://sentry.io/pricing/)
[Sign In](https://sentry.io/auth/login/) [Get Demo](https://sentry.io/demo/) [Get Started](https://sentry.io/signup/)
- Platform
- Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
- Resources
- [Docs](https://docs.sentry.io/)
- [Pricing](https://sentry.io/pricing/)
[Sign In](https://sentry.io/auth/login/) [Get Demo](https://sentry.io/demo/) [Get Started](https://sentry.io/signup/)
[Sentry Answers](https://sentry.io/answers/) \> [Git](https://sentry.io/answers/git/) \> Revert a Git repository to a previous commit
# Revert a Git repository to a previous commit

David Y. —
February 15, 2023
[jump to solution](https://sentry.io/answers/revert-a-git-repository-to-a-previous-commit/#the-solution)
## The Problem
How do I revert a Git repository to a previous commit?
## The Solution
In Git, the word “revert” has a special meaning. You can use the [`git revert`](https://git-scm.com/docs/git-revert) command to return your repository’s files to a previous state without rewriting the commit history. This is done by creating new commits that do the opposite of existing commits, i.e. removing lines and files that were added and adding lines and files that were removed.
To revert the most recently created commit, you can specify its hash or use `HEAD`:
```
git add .
git commit -m "This commit is a mistake"
git revert HEAD # will create a new commit doing the opposite of the one above
```
To revert multiple recent commits, you can specify a range, from oldest to newest. One new commit will be created for each reverted commit.
```
git revert HEAD~3...HEAD # revert the last three commits
```
`git revert` is a good way to restore a previous state while retaining the repository’s edit history. However, in some cases, you may prefer to delete previous commits rather than reverse them. To do this, you can use `git reset --hard`, specifying the commit to return to:
```
git reset --hard HEAD~
```
This will return the repository’s files to their previous state and remove the most recent commit from the current branch’s history. For more on `git reset`, take a look at our answer for [undoing Git commits](https://sentry.io/answers/undo-the-most-recent-local-git-commits/).
## Further Reading
If you’re looking to get a deeper understanding of how application performance monitoring works, take a look at the following articles:
- [Releases Are Better With Commits](https://blog.sentry.io/release-commits/)
- [Improve Your Workflow with Sentry](https://blog.sentry.io/the-sentry-workflow/)
- [11 Habits of Highly Effective Developers](https://syntax.fm/show/778/11-habits-of-highly-effective-developers)
### More Git content
- Resources [What is Distributed Tracing (opens in a new tab)](https://sentry.io/resources/distributed-tracing-explained/)
- Community Series [Identify, Trace, and Fix Endpoint Regression Issues (opens in a new tab)](https://sentry.io/community/series/monitor-endpoint-regression/)
-  [Listen to the Syntax Podcast (opens in a new tab)](https://syntax.fm/?utm_source=sentry&utm_medium=display&utm_campaign=syntax-na-podcastpromo&utm_content=logo-answers-rail-banner-listen)
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
[SEE EPISODES](https://syntax.fm/?utm_source=sentry&utm_medium=display&utm_campaign=syntax-na-podcastpromo&utm_content=logo-answers-rail-banner-listen)
## Related Answers
[Undo git add before commit](https://sentry.io/answers/undo-git-add-before-commit/)
David Y. —
March 15, 2023
[View the change history of a single file in Git](https://sentry.io/answers/view-the-change-history-of-a-single-file-in-git/)
David Y. —
September 15, 2023
[Clone a Git repository to a specific folder](https://sentry.io/answers/clone-a-git-repository-to-a-specific-folder/)
David Y. —
May 15, 2023
[Provide a username and password for Git operation over SSH](https://sentry.io/answers/provide-a-username-and-password-for-git-operation-over-ssh/)
David Y. —
October 15, 2023
Considered "not bad" by 4 million developers and more than 150,000 organizations worldwide, Sentry provides code-level observability to many of the world's best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
[learn more about sentry](https://sentry.io/) [join our discord](https://discord.com/invite/sentry)

### Company
- [About](https://sentry.io/about/)
- [Blog](https://blog.sentry.io/)
- [Careers](https://sentry.io/careers/)
- [Contact Us](https://sentry.io/contact/enterprise/)
- [Trust](https://sentry.io/trust/)
### Platform
- [Error Monitoring](https://sentry.io/product/error-monitoring/)
- [Tracing](https://sentry.io/product/tracing/)
- [Session Replay](https://sentry.io/product/session-replay/)
- [Seer](https://sentry.io/product/seer/)
- [Logs](https://sentry.io/product/logs/)
- [Uptime Monitoring](https://sentry.io/product/uptime-monitoring/)
- [Profiling](https://sentry.io/product/profiling/)
- [Cron Monitoring](https://sentry.io/product/cron-monitoring/)
- [Integrations](https://sentry.io/integrations/)
### Solutions
- [Web / Full Stack Development](https://sentry.io/for/full-stack/)
- [Mobile Crash Reporting](https://sentry.io/solutions/mobile-developers/)
- [Game Crash Reporting](https://sentry.io/solutions/game-developers/)
- [AI Observability](https://sentry.io/solutions/ai-observability/)
- [Application Performance Monitoring](https://sentry.io/solutions/application-performance-monitoring/)
- [Real User Monitoring](https://sentry.io/solutions/real-user-monitoring-rum/)
- [Ecommerce](https://sentry.io/solutions/ecommerce/)
- [Enterprise](https://sentry.io/for/enterprise/)
- [Startups](https://sentry.io/for/startups/)
### Get Help
- [Docs](https://docs.sentry.io/)
- [Help Center](https://help.sentry.io/)
- [Status](https://status.sentry.io/)
- [Dev Resources](https://develop.sentry.dev/getting-started/)
[Terms](https://sentry.io/terms/) [Security & Compliance](https://sentry.io/security/) [Privacy](https://sentry.io/privacy/)
[ Twitter Menu Button](https://x.com/sentry/) [ Github Social Menu Button](https://github.com/getsentry/) [ LinkedIn Menu Button](https://linkedin.com/company/getsentry/) [ Discord Menu Button](https://discord.gg/sentry)
© 2026 • Sentry is a registered Trademark of Functional Software, Inc. |
| Readable Markdown | ## The Problem
How do I revert a Git repository to a previous commit?
## The Solution
In Git, the word “revert” has a special meaning. You can use the [`git revert`](https://git-scm.com/docs/git-revert) command to return your repository’s files to a previous state without rewriting the commit history. This is done by creating new commits that do the opposite of existing commits, i.e. removing lines and files that were added and adding lines and files that were removed.
To revert the most recently created commit, you can specify its hash or use `HEAD`:
```
git add .
git commit -m "This commit is a mistake"
git revert HEAD # will create a new commit doing the opposite of the one above
```
To revert multiple recent commits, you can specify a range, from oldest to newest. One new commit will be created for each reverted commit.
```
git revert HEAD~3...HEAD # revert the last three commits
```
`git revert` is a good way to restore a previous state while retaining the repository’s edit history. However, in some cases, you may prefer to delete previous commits rather than reverse them. To do this, you can use `git reset --hard`, specifying the commit to return to:
```
git reset --hard HEAD~
```
This will return the repository’s files to their previous state and remove the most recent commit from the current branch’s history. For more on `git reset`, take a look at our answer for [undoing Git commits](https://sentry.io/answers/undo-the-most-recent-local-git-commits/).
## Further Reading
If you’re looking to get a deeper understanding of how application performance monitoring works, take a look at the following articles:
- [Releases Are Better With Commits](https://blog.sentry.io/release-commits/)
- [Improve Your Workflow with Sentry](https://blog.sentry.io/the-sentry-workflow/)
- [11 Habits of Highly Effective Developers](https://syntax.fm/show/778/11-habits-of-highly-effective-developers) |
| Shard | 147 (laksa) |
| Root Hash | 17800916657557307547 |
| Unparsed URL | io,sentry!/answers/revert-a-git-repository-to-a-previous-commit/ s443 |