How do I revert a Git repository to a previous commit?
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
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.
Loved by over 4 million developers and more than 90,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.
Here’s a quick look at how Sentry handles your personal information (PII).×
We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.Am I included?
We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII: