âšī¸ 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.5 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://www.geeksforgeeks.org/git/how-to-revert-to-last-commit/ |
| Last Crawled | 2026-03-27 05:03:04 (14 days ago) |
| First Indexed | 2025-07-02 15:35:29 (9 months ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Revert to Last Commit? - GeeksforGeeks |
| Meta Description | Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more., Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. |
| Meta Canonical | null |
| Boilerpipe Text | Last Updated :
6 Jun, 2024
Reverting to the last commit in Git is an important skill for developers who need to undo changes and return their project to a previous state. This article will guide you through various approaches to revert to the last commit, detailing each step to ensure you can effectively manage your Git repository.
Reverting to the last commit means discarding the changes made after the last commit and bringing your working directory back to the state it was in at that commit. This is useful when recent changes have introduced errors, and you need to return to a stable state. There are several ways to accomplish this in Git, each with its own use cases and benefits.
Approaches to Revert to Last Commit in Git are mentioned below:
Table of Content
Using `git reset`
Using `git revert`
Using `git reset`
`git reset` is a powerful command used to undo changes. It can modify the index, the working directory, and the commit history.
Steps:
1. Navigate to your repository:
cd /path/to/your/repository
2. Check the commit history:
git log --oneline
Identify the commit hash (e.g., `a1b2c3d`) you want to reset to.
3. Hard reset to the last commit:
git reset --hard HEAD^
This command will discard all changes after the last commit, including changes in the working directory and the staging area.
Alternatively, if you have the commit hash:
git reset --hard a1b2c3d
4. Force push (if working on a shared repository):
git push --force
Example Demonstration:
Using `git revert`
`git revert` creates a new commit that undoes the changes from a previous commit.
Steps:
1. Navigate to your repository:
cd /path/to/your/repository
2. Revert the last commit:
git revert HEAD
This command creates a new commit that is the inverse of the last commit.
3. Resolve conflicts (if any):
Follow the on-screen instructions to resolve any merge conflicts, then commit the changes.
4. Push the changes (if working on a shared repository):
git push
Example Demonstration:
Conclusion
Reverting to the last commit is a common task in Git that can be achieved using `git reset`, or `git revert`. Each method has its specific use cases:
`git reset` is ideal for discarding local changes and resetting the commit history.
`git revert` is perfect for maintaining history while undoing changes. |
| Markdown | [](https://www.geeksforgeeks.org/)

- Sign In
- [Courses]()
- [Tutorials]()
- [Interview Prep]()
- [DSA](https://www.geeksforgeeks.org/dsa/dsa-tutorial-learn-data-structures-and-algorithms/)
- [Practice Problems](https://www.geeksforgeeks.org/explore)
- [C](https://www.geeksforgeeks.org/c/c-programming-language/)
- [C++](https://www.geeksforgeeks.org/cpp/c-plus-plus/)
- [Java](https://www.geeksforgeeks.org/java/java/)
- [Python](https://www.geeksforgeeks.org/python/python-programming-language-tutorial/)
- [JavaScript](https://www.geeksforgeeks.org/javascript/javascript-tutorial/)
- [Data Science](https://www.geeksforgeeks.org/data-science/data-science-for-beginners/)
- [Machine Learning](https://www.geeksforgeeks.org/machine-learning/machine-learning/)
- [Courses](https://www.geeksforgeeks.org/courses)
# How to Revert to Last Commit?
Last Updated : 6 Jun, 2024
Reverting to the last commit in Git is an important skill for developers who need to undo changes and return their project to a previous state. This article will guide you through various approaches to revert to the last commit, detailing each step to ensure you can effectively manage your Git repository.
Reverting to the last commit means discarding the changes made after the last commit and bringing your working directory back to the state it was in at that commit. This is useful when recent changes have introduced errors, and you need to return to a stable state. There are several ways to accomplish this in Git, each with its own use cases and benefits.
Approaches to Revert to Last Commit in Git are mentioned below:
Table of Content
- [Using \`git reset\`](https://www.geeksforgeeks.org/git/how-to-revert-to-last-commit/#approach-1-using-git-reset)
- [Using \`git revert\`](https://www.geeksforgeeks.org/git/how-to-revert-to-last-commit/#approach-2-using-git-revert)
## Using \`git reset\`
\`git reset\` is a powerful command used to undo changes. It can modify the index, the working directory, and the commit history.
### Steps:
1\. Navigate to your repository:
```
cd /path/to/your/repository
```
2\. Check the commit history:
```
git log --oneline
```
Identify the commit hash (e.g., \`a1b2c3d\`) you want to reset to.
3\. Hard reset to the last commit:
```
git reset --hard HEAD^
```
This command will discard all changes after the last commit, including changes in the working directory and the staging area.
Alternatively, if you have the commit hash:
```
git reset --hard a1b2c3d
```
4\. Force push (if working on a shared repository):
```
git push --force
```
### Example Demonstration:
## Using \`git revert\`
\`git revert\` creates a new commit that undoes the changes from a previous commit.
### Steps:
1\. Navigate to your repository:
```
cd /path/to/your/repository
```
2\. Revert the last commit:
```
git revert HEAD
```
This command creates a new commit that is the inverse of the last commit.
3\. Resolve conflicts (if any):
Follow the on-screen instructions to resolve any merge conflicts, then commit the changes.
4\. Push the changes (if working on a shared repository):
```
git push
```
### Example Demonstration:
## Conclusion
Reverting to the last commit is a common task in Git that can be achieved using \`git reset\`, or \`git revert\`. Each method has its specific use cases:
- \`git reset\` is ideal for discarding local changes and resetting the commit history.
- \`git revert\` is perfect for maintaining history while undoing changes.
Comment
[M](https://www.geeksforgeeks.org/user/mohammedraziullahansari/)
[mohammedraziullahansari](https://www.geeksforgeeks.org/user/mohammedraziullahansari/)
0
Article Tags:
Article Tags:
[Web Technologies](https://www.geeksforgeeks.org/category/web-technologies/)
[Git](https://www.geeksforgeeks.org/category/git/)
### Explore
[](https://www.geeksforgeeks.org/)

Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)

Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
[](https://geeksforgeeksapp.page.link/gfg-app)[](https://geeksforgeeksapp.page.link/gfg-app)
- Company
- [About Us](https://www.geeksforgeeks.org/about/)
- [Legal](https://www.geeksforgeeks.org/legal/)
- [Privacy Policy](https://www.geeksforgeeks.org/legal/privacy-policy/)
- [Contact Us](https://www.geeksforgeeks.org/about/contact-us/)
- [Advertise with us](https://www.geeksforgeeks.org/advertise-with-us/)
- [GFG Corporate Solution](https://www.geeksforgeeks.org/gfg-corporate-solution/)
- [Campus Training Program](https://www.geeksforgeeks.org/campus-training-program/)
- Explore
- [POTD](https://www.geeksforgeeks.org/problem-of-the-day)
- [Job-A-Thon](https://practice.geeksforgeeks.org/events/rec/job-a-thon/)
- [Blogs](https://www.geeksforgeeks.org/category/blogs/?type=recent)
- [Nation Skill Up](https://www.geeksforgeeks.org/nation-skill-up/)
- Tutorials
- [Programming Languages](https://www.geeksforgeeks.org/computer-science-fundamentals/programming-language-tutorials/)
- [DSA](https://www.geeksforgeeks.org/dsa/dsa-tutorial-learn-data-structures-and-algorithms/)
- [Web Technology](https://www.geeksforgeeks.org/web-tech/web-technology/)
- [AI, ML & Data Science](https://www.geeksforgeeks.org/machine-learning/ai-ml-and-data-science-tutorial-learn-ai-ml-and-data-science/)
- [DevOps](https://www.geeksforgeeks.org/devops/devops-tutorial/)
- [CS Core Subjects](https://www.geeksforgeeks.org/gate/gate-exam-tutorial/)
- [Interview Preparation](https://www.geeksforgeeks.org/aptitude/interview-corner/)
- [Software and Tools](https://www.geeksforgeeks.org/websites-apps/software-and-tools-a-to-z-list/)
- Courses
- [ML and Data Science](https://www.geeksforgeeks.org/courses/category/machine-learning-data-science)
- [DSA and Placements](https://www.geeksforgeeks.org/courses/category/dsa-placements)
- [Web Development](https://www.geeksforgeeks.org/courses/category/development-testing)
- [Programming Languages](https://www.geeksforgeeks.org/courses/category/programming-languages)
- [DevOps & Cloud](https://www.geeksforgeeks.org/courses/category/cloud-devops)
- [GATE](https://www.geeksforgeeks.org/courses/category/gate)
- [Trending Technologies](https://www.geeksforgeeks.org/courses/category/trending-technologies/)
- Videos
- [DSA](https://www.geeksforgeeks.org/videos/category/sde-sheet/)
- [Python](https://www.geeksforgeeks.org/videos/category/python/)
- [Java](https://www.geeksforgeeks.org/videos/category/java-w6y5f4/)
- [C++](https://www.geeksforgeeks.org/videos/category/c/)
- [Web Development](https://www.geeksforgeeks.org/videos/category/web-development/)
- [Data Science](https://www.geeksforgeeks.org/videos/category/data-science/)
- [CS Subjects](https://www.geeksforgeeks.org/videos/category/cs-subjects/)
- Preparation Corner
- [Interview Corner](https://www.geeksforgeeks.org/interview-prep/interview-corner/)
- [Aptitude](https://www.geeksforgeeks.org/aptitude/aptitude-questions-and-answers/)
- [Puzzles](https://www.geeksforgeeks.org/aptitude/puzzles/)
- [GfG 160](https://www.geeksforgeeks.org/courses/gfg-160-series)
- [System Design](https://www.geeksforgeeks.org/system-design/system-design-tutorial/)
[@GeeksforGeeks, Sanchhaya Education Private Limited](https://www.geeksforgeeks.org/), [All rights reserved](https://www.geeksforgeeks.org/copyright-information/)
![]() |
| Readable Markdown | Last Updated : 6 Jun, 2024
Reverting to the last commit in Git is an important skill for developers who need to undo changes and return their project to a previous state. This article will guide you through various approaches to revert to the last commit, detailing each step to ensure you can effectively manage your Git repository.
Reverting to the last commit means discarding the changes made after the last commit and bringing your working directory back to the state it was in at that commit. This is useful when recent changes have introduced errors, and you need to return to a stable state. There are several ways to accomplish this in Git, each with its own use cases and benefits.
Approaches to Revert to Last Commit in Git are mentioned below:
Table of Content
- [Using \`git reset\`](https://www.geeksforgeeks.org/git/how-to-revert-to-last-commit/#approach-1-using-git-reset)
- [Using \`git revert\`](https://www.geeksforgeeks.org/git/how-to-revert-to-last-commit/#approach-2-using-git-revert)
## Using \`git reset\`
\`git reset\` is a powerful command used to undo changes. It can modify the index, the working directory, and the commit history.
### Steps:
1\. Navigate to your repository:
```
cd /path/to/your/repository
```
2\. Check the commit history:
```
git log --oneline
```
Identify the commit hash (e.g., \`a1b2c3d\`) you want to reset to.
3\. Hard reset to the last commit:
```
git reset --hard HEAD^
```
This command will discard all changes after the last commit, including changes in the working directory and the staging area.
Alternatively, if you have the commit hash:
```
git reset --hard a1b2c3d
```
4\. Force push (if working on a shared repository):
```
git push --force
```
### Example Demonstration:
## Using \`git revert\`
\`git revert\` creates a new commit that undoes the changes from a previous commit.
### Steps:
1\. Navigate to your repository:
```
cd /path/to/your/repository
```
2\. Revert the last commit:
```
git revert HEAD
```
This command creates a new commit that is the inverse of the last commit.
3\. Resolve conflicts (if any):
Follow the on-screen instructions to resolve any merge conflicts, then commit the changes.
4\. Push the changes (if working on a shared repository):
```
git push
```
### Example Demonstration:
## Conclusion
Reverting to the last commit is a common task in Git that can be achieved using \`git reset\`, or \`git revert\`. Each method has its specific use cases:
- \`git reset\` is ideal for discarding local changes and resetting the commit history.
- \`git revert\` is perfect for maintaining history while undoing changes. |
| Shard | 103 (laksa) |
| Root Hash | 12046344915360636903 |
| Unparsed URL | org,geeksforgeeks!www,/git/how-to-revert-to-last-commit/ s443 |