ℹ️ 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 | 1.2 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://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/ |
| Last Crawled | 2026-03-08 23:20:27 (1 month ago) |
| First Indexed | 2021-11-10 09:16:55 (4 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Revert a Git Repository to a Previous Commit | CircleCoder |
| Meta Description | Short answers to the question how to revert a git repository to a previous commit. |
| Meta Canonical | null |
| Boilerpipe Text | Scenario A: Temporarily Switch to a Different Commit
1
$
git checkout 0d1d7fc32
The above command will:
checkout the desired commit
detach your HEAD (leave you with no branch checked out)
Scenario B: Hard Delete Unpublished Commits
1
$
git reset
--hard
0d1d7fc32
The above command will:
destroy any local modifications
if you want to keep uncommitted work, use
git stash
Scenario C: Undo Published Commits With New Commits
1
$
git revert 0d1d7fc32 25eee4ca
or
1
$
git revert
--no-commit
0d1d7fc32..HEAD
or
1
$
git revert
-m
1 <merge_commit_sha>
The first command will:
create two separate revert commits
revert the two commits
The second command will:
revert everything from the HEAD back to the commit hash
--no-commit
flag lets git revert all the commits at once
The third command will:
revert a merge commit |
| Markdown | ### [CircleCoder](https://circlecoder.com/index.html)
- [Posts](https://circlecoder.com/index.html)
- [Topics](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
[All Topics](https://circlecoder.com/topics.html)
[LeetCode](https://circlecoder.com/leetcode-solution-list/)
[LeetCode Database](https://circlecoder.com/leetcode-database-solution-list/)
[Git Short Answers](https://circlecoder.com/git-short-answers-list/)
[MySQL](https://circlecoder.com/mysql-tutorial-list/)
[Operating System](https://circlecoder.com/operating-system-topic-list/)
[Object Oriented Design](https://circlecoder.com/object-oriented-design-topic-list/)
[C++ Concepts](https://circlecoder.com/cplusplus-concept-list/)
Topics
Share
# How to Revert a Git Repository to a Previous Commit
##### Scenario A: Temporarily Switch to a Different Commit
```
```
The above command will:
- checkout the desired commit
- detach your HEAD (leave you with no branch checked out)
##### Scenario B: Hard Delete Unpublished Commits
```
```
The above command will:
- destroy any local modifications
- if you want to keep uncommitted work, use `git stash`
##### Scenario C: Undo Published Commits With New Commits
```
```
or
```
```
or
```
```
The first command will:
- create two separate revert commits
- revert the two commits
The second command will:
- revert everything from the HEAD back to the commit hash
- `--no-commit` flag lets git revert all the commits at once
The third command will:
- revert a merge commit
09 Nov 2021
- [Git](https://circlecoder.com/categories#Git)
- [\#Git Revert](https://circlecoder.com/tags#Git-Revert)
[« How to Modify Existing Unpushed Commit Messages](https://circlecoder.com/how-to-modify-existing-unpushed-commit-messages/) [What is the Difference Between Git Pull and Git Fetch »](https://circlecoder.com/what-is-the-difference-between-git-pull-and-git-fetch/)
## Related Posts
## [What is the Difference Between Git Pull and Git Fetch](https://circlecoder.com/what-is-the-difference-between-git-pull-and-git-fetch/)
#### Short answers to the question what is the difference between...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Pull](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
09 Nov 2021
## [How to Revert a Git Repository to a Previous Commit](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
#### Short answers to the question how to revert a git...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Revert](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
09 Nov 2021
## [How to Modify Existing Unpushed Commit Messages](https://circlecoder.com/how-to-modify-existing-unpushed-commit-messages/)
#### Short answers to the question how to modify existing unpushed...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Commit](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
09 Nov 2021
## [How to Undo a Git Add Before Commit](https://circlecoder.com/how-to-undo-a-git-add-before-commit/)
#### Short answers to the question how to undo a git...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Reset](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
04 Nov 2021
## [How to Rename a Local Git Branch](https://circlecoder.com/how-to-rename-a-local-git-branch/)
#### Short answers to the question how to rename a local...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Branch](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
04 Nov 2021
## [How to Delete a Git Branch Locally and Remotely](https://circlecoder.com/how-to-delete-a-git-branch-locally-and-remotely/)
#### Short answers to the question how to delete a git...
[Git](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/) [Git Branch](https://circlecoder.com/how-to-revert-a-git-repository-to-a-previous-commit/)
04 Nov 2021
Copyright © 2024 CircleCoder \| All Rights Reserved \| [Phair.io](https://phair.io/) \| [Patternful.ai](https://patternful.ai/) |
| Readable Markdown | ##### Scenario A: Temporarily Switch to a Different Commit
```
```
The above command will:
- checkout the desired commit
- detach your HEAD (leave you with no branch checked out)
##### Scenario B: Hard Delete Unpublished Commits
```
```
The above command will:
- destroy any local modifications
- if you want to keep uncommitted work, use `git stash`
##### Scenario C: Undo Published Commits With New Commits
```
```
or
```
```
or
```
```
The first command will:
- create two separate revert commits
- revert the two commits
The second command will:
- revert everything from the HEAD back to the commit hash
- `--no-commit` flag lets git revert all the commits at once
The third command will:
- revert a merge commit |
| Shard | 191 (laksa) |
| Root Hash | 1093013983554932391 |
| Unparsed URL | com,circlecoder!/how-to-revert-a-git-repository-to-a-previous-commit/ s443 |