ā¹ļø 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://phoenixnap.com/kb/git-revert-last-commit |
| Last Crawled | 2026-04-11 14:32:33 (18 minutes ago) |
| First Indexed | 2020-03-19 16:48:18 (6 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Git Revert Commit: How to Revert Previous Commit |
| Meta Description | Learn how to revert your Git commits the easy way. This tutorial has all the commands you need with examples, git reset & git revert. Undo the last commit! |
| Meta Canonical | null |
| Boilerpipe Text | Home
Ā»
KB
Ā»
SysAdmin
Ā»
Git Revert Commit: How to Undo Last Commit
Topics:
Git
is a popular project tracking application. As a project progresses through different revisions, those revisions are published as aĀ
commit
. A commit represents a checkpoint, where a copy of the project is saved at a specific point.
This guide shows you how to undo the last commit in git.
Prerequisites
An existing project in Git
Access to a terminal window/command line
Note:
If you wish to undo a commit to correct an error in the commit message, there is a better way to do it. Learn how to
change a Git commit message
.
How to Revert Commit
Git offers many features to manage your project from different historical commits. You can view and revert a previous commit, either published or unpublished.
Read on to learn how to identify and revert a published commit. Also, if you want to learn more about Git, check out our article on
how does Git work
.
Identifying the Commit
AĀ hashĀ is an alphanumeric code that identifies each commit. Enter the following command to display a commit hash:
git log
The hash is necessary to display or manage a specific commit.
To analyze the status of your project from a previous commit, use theĀ checkoutĀ command:
git checkout [hash]
When using a hash with a Git command, there is no need to type it in its entirety. The first few unique characters are enough for Git to identify an entry accurately.
Note:
Find out how to use
Git checkout tags
and why they are useful for your development project.
Git Revert: Reverting the Last Git Commit
Once a commit is uploaded to the server, it creates a more permanent project log. It is not advisable to useĀ
reset
Ā in this case as other developers may have retrieved the updated project already.
Deleting updates from one system may cause conflicts with other team members. Instead, use theĀ
revert
Ā command:
git revert [hash]
Make sure to enter the code for the hash you want to revert to. The system asks you to enter a specific commit message for the changes theĀ
revert
Ā command is going to perform.
This action creates a new commit based on the one you specified, with aĀ
revert
tag. This acts as a log, showing that the commit was published and then reverted (instead of pretending it never happened).
Note:
Learn how to use
Git cherry-pick
to select and apply a single commit from one branch to another.
Git Reset: Revert Unpublished Commits
An
unpublished commit
is an update committed in Git but that has not been uploaded to a server. To reset to a previous commit, before any changes were made:
git reset --hard [hash]
This command wipes the slate clean back to the previous commit. Any changes you made will be lost after using the
reset --hard command
.
If you want to preserve your work, you can use
Git stash
:
git stash
git reset --hard [hash]
git stash pop
TheĀ
stash
Ā
command saves the work you did, andĀ
stash pop
retrieves those changes after the reset. Alternately you can use the following:
git reset --soft [hash]
This command resets the commit history, but it leaves your working directory and staging index as-is.
Note:
Git stash allows users to save their uncommitted files and work in progress to a local stash. Learn how to
Git stash specific files
.
Git Amend: Modify the Last Commit
To modify the most recent commit, use the
git commit --amend
command. This command replaces the last commit with the amended commit without altering the snapshot.
The
--amend
flag is usually used to fix minor mistakes.
For instance, you want to commit a couple of files in a single snapshot but forget to add one of the files before committing. This issue is easily solved using the
--amend
option.
First, you add the missing file using:
git add file2.py
Then, run the command:
git commit --amend --no-edit
The
--no-edit
option amends the commit without changing the commit message.
Conclusion
You now know how to use the
revert
and
reset
commands to undo changes and revert to a previous commit. Additionally, you have learned how to check the status of your current commit.
Remember not to use
reset
for published commits as it may lead to version conflicts.
Was this article helpful?
Yes
No |
| Markdown | - [Call](https://phoenixnap.com/kb/git-revert-last-commit)
- [Support](tel:1-855-330-1509)
- [Sales](tel:1-877-588-5918)
- [Login](https://phoenixnap.com/kb/git-revert-last-commit)
- [Bare Metal Cloud](https://bmc.phoenixnap.com/)
- [Admin Hub](https://admin.phoenixnap.com/)
- [Partners](https://phoenixnap.com/partners)
- [COLOCATION](https://phoenixnap.com/colocation)
- [Colocation Premier Carrier Hotel](https://phoenixnap.com/colocation)
- [Data Center as a Service Solutions for Digital Transformation](https://phoenixnap.com/colocation/data-center-as-a-service)
- [Data Center as a Service Overview](https://phoenixnap.com/colocation/data-center-as-a-service)
- [Hardware as a Service Flexible Hardware Leasing](https://phoenixnap.com/colocation/hardware-as-a-service)
- [Bare Metal Cloud API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud)
- [Object Storage S3 API Compatible Storage Service](https://phoenixnap.com/object-storage)
- [Meet-Me Room The Interconnectivity Hub](https://phoenixnap.com/colocation/meet-me-room)
- [Meet-Me Room Overview](https://phoenixnap.com/colocation/meet-me-room)
- [AWS Direct Connect Dedicated Link to Amazon Cloud](https://phoenixnap.com/colocation/aws-direct-connect)
- [Google Cloud Interconnect Private Connectivity to Google Cloud](https://phoenixnap.com/google-cloud-interconnect)
- [Megaport Cloud Router Simplified Multi-Cloud Connections](https://phoenixnap.com/offers/megaport-cloud-router)
- [All Carriers Global Interconnectivity Options](https://phoenixnap.com/colocation/all-carriers)
- [Schedule a Tour Guided Virtual Data Center Tour](https://phoenixnap.com/phoenix-data-center-virtual-tour)
- [Data Center Locations Global Data Center Footprint](https://phoenixnap.com/colocation/data-center-locations)
- [Data Center Locations Overview](https://phoenixnap.com/colocation/data-center-locations)
- [Phoenix, AZ The Largest Fiber Backbone in the U.S.](https://phoenixnap.com/colocation/phoenix)
- [Amsterdam, NL The Connectivity Hub of Europe](https://phoenixnap.com/colocation/amsterdam)
- [BARE METAL CLOUD](https://phoenixnap.com/bare-metal-cloud)
- [Platform API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud)
- [Platform Overview](https://phoenixnap.com/bare-metal-cloud)
- [Infrastructure As Code DevOps Integrations](https://phoenixnap.com/bare-metal-cloud/infrastructure-as-code)
- [BMC vs. Dedicated Servers Choose the Best Option](https://phoenixnap.com/bare-metal-cloud-vs-dedicated-servers)
- [Pricing Instance pricing and cost estimation](https://phoenixnap.com/kb/git-revert-last-commit)
- [Instance Pricing See All Configurations](https://phoenixnap.com/bare-metal-cloud/instances)
- [Pricing Calculator Get an Estimate](https://phoenixnap.com/cloud-pricing-calculator)
- [Network/IP Pricing Flexible IP Pricing](https://phoenixnap.com/bare-metal-cloud/ip-pricing)
- [Kubernetes Solutions Streamlined Kubernetes Management](https://phoenixnap.com/kb/git-revert-last-commit)
- [Rancher Deployment One-Click Kubernetes Deployment](https://phoenixnap.com/bare-metal-cloud/rancher-deployment)
- [CPUs Next Gen Intel Processors](https://phoenixnap.com/kb/git-revert-last-commit)
- [Xeon 6 6700-series with E-Cores Supercharge Cloud-Native Workloads](https://phoenixnap.com/bare-metal-cloud/intel-xeon-6-processors-with-e-cores)
- [Intel® Core⢠i9 14900K Ideal for Gaming, Streaming, and Content Creation](https://phoenixnap.com/bare-metal-cloud/intel-core-i9-14900k)
- [5th Gen Intel Xeon Scalable CPUs Boost Data-Intensive Workloads](https://phoenixnap.com/bare-metal-cloud/5th-gen-intel-xeon-scalable-processors)
- [HPE Ampere Altra Q80-30 HPEĀ® ProLiant RL300 as a service](https://phoenixnap.com/bare-metal-cloud/hpe-proliant-rl300)
- [Alliances Technology Partnerships](https://phoenixnap.com/bare-metal-cloud/technology-ecosystem)
- [Ecosystem Underlying Technologies](https://phoenixnap.com/bare-metal-cloud/technology-ecosystem)
- [NetrisOS VPC networking on bare metal](https://phoenixnap.com/bare-metal-cloud/netris)
- [Storage Options Flexible Storage Solutions](https://phoenixnap.com/kb/git-revert-last-commit)
- [Object Storage S3-Compatible Storage Solution](https://phoenixnap.com/object-storage)
- [Network File Storage All-Flash Scale-Out Storage Resources](https://phoenixnap.com/network-file-storage)
- [GPU Servers For AI/ML and HPC workloads](https://phoenixnap.com/kb/git-revert-last-commit)
- [Intel Max 1100 GPUs 1 system. 2 GPUs. Amazing performance.](https://phoenixnap.com/bare-metal-cloud/gpu-servers)
- [HYBRID CLOUD](https://phoenixnap.com/security/data-security-cloud)
- [Hybrid Cloud Overview](https://phoenixnap.com/cloud-services/hybrid-cloud-solutions)
- [Object Storage S3 Compatible Storage Solution](https://phoenixnap.com/object-storage)
- [Bare Metal Cloud API-Driven Dedicated Servers](https://phoenixnap.com/bare-metal-cloud)
- [Alternative Cloud Provider Overcome Public Cloud Limitations](https://phoenixnap.com/cloud-services/alternative-cloud-provider)
- [Backup Solutions Veeam-Powered Services](https://phoenixnap.com/backup-restore)
- [Disaster Recovery VMware, Veeam, Zerto](https://phoenixnap.com/disaster-recovery-as-a-service-draas)
- [Veeam Cloud Connect Backup and Replication](https://phoenixnap.com/backup-restore/veeam-cloud-connect)
- [Managed Backup for Microsoft 365 Veeam-Powered Service](https://phoenixnap.com/backup-restore/microsoft-365-backup)
- [NETWORK](https://phoenixnap.com/network)
- [Network Overview Global Network Footprint](https://phoenixnap.com/network)
- [Network Locations U.S., Europe, APAC, LATAM](https://phoenixnap.com/network/locations)
- [Speed Test Download Speed Test](https://phoenixnap.com/network/speed-test)
- [LEARN](https://phoenixnap.com/kb)
- [Blog IT Tips and Tricks](https://phoenixnap.com/blog/)
- [Resource Library Knowledge Resources](https://phoenixnap.com/company/resource-library)
- [Glossary IT Terms and Definitions](https://phoenixnap.com/glossary/)
- [Events Let's Meet\!](https://phoenixnap.com/company/it-events)
- [Newsroom Media Library](https://phoenixnap.com/company/press)
- [Developers Development Resources Portal](https://developers.phoenixnap.com/)
- [APIs Access Our Public APIs](https://developers.phoenixnap.com/apis)
- [GitHub Public Code Repositories](https://github.com/phoenixnap)
[Home](https://phoenixnap.com/) Ā» [KB](https://phoenixnap.com/kb/) Ā» [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) Ā» Git Revert Commit: How to Undo Last Commit
# Git Revert Commit: How to Undo Last Commit


By
[Vladimir Kaplarevic](https://phoenixnap.com/kb/author/vladimirk)
Published:
March 3, 2022
Topics:
[git](https://phoenixnap.com/kb/tag/git)
[Git](https://phoenixnap.com/kb/what-is-git) is a popular project tracking application. As a project progresses through different revisions, those revisions are published as a [commit](https://phoenixnap.com/kb/git-commit). A commit represents a checkpoint, where a copy of the project is saved at a specific point.
**This guide shows you how to undo the last commit in git.**


Prerequisites
- An existing project in Git
- Access to a terminal window/command line
**Note:** If you wish to undo a commit to correct an error in the commit message, there is a better way to do it. Learn how to [change a Git commit message](https://phoenixnap.com/kb/git-change-commit-message).
## How to Revert Commit
Git offers many features to manage your project from different historical commits. You can view and revert a previous commit, either published or unpublished.
Read on to learn how to identify and revert a published commit. Also, if you want to learn more about Git, check out our article on [how does Git work](https://phoenixnap.com/kb/how-git-works).
### Identifying the Commit
A hash is an alphanumeric code that identifies each commit. Enter the following command to display a commit hash:
```
git log
```
The hash is necessary to display or manage a specific commit.


To analyze the status of your project from a previous commit, use the checkout command:
```
git checkout [hash]
```
When using a hash with a Git command, there is no need to type it in its entirety. The first few unique characters are enough for Git to identify an entry accurately.
**Note:** Find out how to use [Git checkout tags](https://phoenixnap.com/kb/git-checkout-tag) and why they are useful for your development project.
### Git Revert: Reverting the Last Git Commit
Once a commit is uploaded to the server, it creates a more permanent project log. It is not advisable to use **reset** in this case as other developers may have retrieved the updated project already.
Deleting updates from one system may cause conflicts with other team members. Instead, use the **revert** command:
```
git revert [hash]
```
Make sure to enter the code for the hash you want to revert to. The system asks you to enter a specific commit message for the changes the **revert** command is going to perform.


This action creates a new commit based on the one you specified, with a **`revert`** tag. This acts as a log, showing that the commit was published and then reverted (instead of pretending it never happened).
**Note:** Learn how to use [Git cherry-pick](https://phoenixnap.com/kb/git-cherry-pick) to select and apply a single commit from one branch to another.
## Git Reset: Revert Unpublished Commits
An **unpublished commit** is an update committed in Git but that has not been uploaded to a server. To reset to a previous commit, before any changes were made:
```
git reset --hard [hash]
```
This command wipes the slate clean back to the previous commit. Any changes you made will be lost after using the [reset --hard command](https://phoenixnap.com/kb/git-reset-hard).
If you want to preserve your work, you can use [Git stash](https://phoenixnap.com/kb/git-stash):
```
git stash
git reset --hard [hash]
git stash pop
```
The **`stash`** command saves the work you did, and **`stash pop`** retrieves those changes after the reset. Alternately you can use the following:
```
git reset --soft [hash]
```
This command resets the commit history, but it leaves your working directory and staging index as-is.
**Note:** Git stash allows users to save their uncommitted files and work in progress to a local stash. Learn how to [Git stash specific files](https://phoenixnap.com/kb/git-stash-specific-files).
## Git Amend: Modify the Last Commit
To modify the most recent commit, use the **`git commit --amend`** command. This command replaces the last commit with the amended commit without altering the snapshot.
The **`--amend`** flag is usually used to fix minor mistakes.
For instance, you want to commit a couple of files in a single snapshot but forget to add one of the files before committing. This issue is easily solved using the **`--amend`** option.
First, you add the missing file using:
```
git add file2.py
```
Then, run the command:
```
git commit --amend --no-edit
```
The **`--no-edit`** option amends the commit without changing the commit message.
**Note:** If you need to restore a missing repository, refer to our guide [How to Restore a Git Repository](https://phoenixnap.com/kb/restore-git-repository).
Conclusion
You now know how to use the **`revert`** and **`reset`** commands to undo changes and revert to a previous commit. Additionally, you have learned how to check the status of your current commit.
Remember not to use **`reset`** for published commits as it may lead to version conflicts.
Was this article helpful?
YesNo
Contents
- [How to Revert Commit](https://phoenixnap.com/kb/git-revert-last-commit#How_to_Revert_Commit)
- [Identifying the Commit](https://phoenixnap.com/kb/git-revert-last-commit#Identifying_the_Commit)
- [Git Revert: Reverting the Last Git Commit](https://phoenixnap.com/kb/git-revert-last-commit#Git_Revert_Reverting_the_Last_Git_Commit)
- [Git Reset: Revert Unpublished Commits](https://phoenixnap.com/kb/git-revert-last-commit#Git_Reset_Revert_Unpublished_Commits)
- [Git Amend: Modify the Last Commit](https://phoenixnap.com/kb/git-revert-last-commit#Git_Amend_Modify_the_Last_Commit)
Subscribe to our newsletter
[SUBSCRIBE](https://phoenixnap.com/developers-monthly-newsletter)
Next you should read
[](https://phoenixnap.com/kb/vim-undo-redo)
[DevOps and Development](https://phoenixnap.com/kb/category/devops-and-development) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin)
[How to Undo and Redo Changes in Vim / Vi](https://phoenixnap.com/kb/vim-undo-redo)
[](https://phoenixnap.com/kb/git-switch-branch)
[DevOps and Development](https://phoenixnap.com/kb/category/devops-and-development) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin)
[How To Switch Branch on Git](https://phoenixnap.com/kb/git-switch-branch)
[](https://phoenixnap.com/kb/how-to-install-git-centos-8)
[DevOps and Development](https://phoenixnap.com/kb/category/devops-and-development) [Web Servers](https://phoenixnap.com/kb/category/web-servers)
[How to Install Git on CentOS 8](https://phoenixnap.com/kb/how-to-install-git-centos-8)
[](https://phoenixnap.com/kb/how-to-rename-git-branch-local-remote)
[DevOps and Development](https://phoenixnap.com/kb/category/devops-and-development) [SysAdmin](https://phoenixnap.com/kb/category/sysadmin)
[How To Rename a Local and Remote Git Branch](https://phoenixnap.com/kb/how-to-rename-git-branch-local-remote)
CONTACT US
[Get a Quote](https://phoenixnap.com/contact-us)
[Support (1-855-330-1509)](tel:1-855-330-1509)
[Sales (1-877-588-5918)](tel:1-877-588-5918)
- [Colocation](https://phoenixnap.com/colocation)
- [Phoenix](https://phoenixnap.com/colocation/phoenix)
- [Ashburn](https://phoenixnap.com/colocation/ashburn)
- [Amsterdam](https://phoenixnap.com/colocation/amsterdam)
- [Atlanta](https://phoenixnap.com/colocation/atlanta)
- [Belgrade](https://phoenixnap.com/colocation/belgrade)
- [Singapore](https://phoenixnap.com/colocation/singapore)
- [Shipping Instructions](https://phoenixnap.com/colocation/shipping-instructions)
RECENT POSTS
[jq Command: How to Process and Transform JSON Data](https://phoenixnap.com/kb/jq)
[ModuleNotFoundError in Python: Causes and Solutions](https://phoenixnap.com/kb/module-not-found-error-python)
[Kill Screen Session in Linux, macOS, Windows](https://phoenixnap.com/kb/kill-screen-session)
[Append Dictionary to Dictionary in Python](https://phoenixnap.com/kb/python-merge-dictionaries)
["Invalid Reference Format" Error in Docker: How to Fix](https://phoenixnap.com/kb/docker-invalid-reference-format)
- [Servers](https://phoenixnap.com/servers/dedicated)
- [Bare Metal Cloud](https://phoenixnap.com/bare-metal-cloud)
- [Dedicated Servers](https://phoenixnap.com/servers/dedicated)
- [Database Servers](https://phoenixnap.com/servers/database)
- [Virtualization Servers](https://phoenixnap.com/servers/virtualization)
- [High Performance Computing (HPC) Servers](https://phoenixnap.com/servers/high-performance-computing-hpc)
- [Dedicated Streaming Servers](https://phoenixnap.com/servers/streaming)
- [Dedicated Game Servers](https://phoenixnap.com/servers/dedicated-game-servers)
- [Dedicated Storage Servers](https://phoenixnap.com/servers/storage)
- [SQL Server Hosting](https://phoenixnap.com/servers/sql-server-hosting)
- [Dedicated Servers in Amsterdam](https://phoenixnap.com/dedicated-servers-amsterdam-netherlands)
- [Cloud Servers in Europe](https://phoenixnap.com/cloud-services/cloud-servers-europe)
- [Big Memory Infrastructure](https://phoenixnap.com/bare-metal-cloud/big-memory-infrastructure)
- [Buy Now](https://admin.phoenixnap.com/wap-pncpadmin-shell/orderForm?bmbPath=/order-form?currencyCode=usd)
- [BMC portal](https://signup.bmc.phoenixnap.com/)
CLOUD SERVICES
- [Data Security Cloud](https://phoenixnap.com/security/data-security-cloud)
- [Managed Private Cloud](https://phoenixnap.com/private)
- [Object Storage](https://phoenixnap.com/object-storage)
- [Solutions](https://phoenixnap.com/infrastructure-solutions)
- [Disaster Recovery](https://phoenixnap.com/infrastructure-solutions/disaster-recovery-services)
- [Web Hosting Reseller](https://phoenixnap.com/reseller-hosting)
- [SaaS Hosting](https://phoenixnap.com/infrastructure-solutions/saas-hosting)
COMPLIANCE
- [HIPAA Ready Hosting](https://phoenixnap.com/compliance/hipaa-compliant-hosting)
- [PCI Compliant Hosting](https://phoenixnap.com/compliance/pci-compliant-hosting)
- [Privacy Center](https://phoenixnap.com/)
- [Do not sell or share my personal information](https://phoenixnap.com/)
NEEDS
- [Disaster Recovery Solutions](https://phoenixnap.com/infrastructure-solutions/disaster-recovery-services)
- [High Availability Solutions](https://phoenixnap.com/infrastructure-solutions/high-availability-solutions)
- [Cloud Evaluation](https://phoenixnap.com/offers/cloud-evaluation-demo)
INDUSTRIES
- [Web Hosting Providers](https://phoenixnap.com/reseller-hosting)
- [Legal](https://phoenixnap.com/infrastructure-solutions/legal-it)
- [MSPs & VARs](https://phoenixnap.com/infrastructure-solutions/it-partners)
- [Media Hosting](https://phoenixnap.com/infrastructure-solutions/media-hosting)
- [Online Gaming](https://phoenixnap.com/infrastructure-solutions/online-gaming)
- [SaaS Hosting Solutions](https://phoenixnap.com/infrastructure-solutions/saas-hosting)
- [Ecommerce Hosting Solutions](https://phoenixnap.com/infrastructure-solutions/ecommerce-hosting)
COMPANY
- [About phoenixNAP](https://phoenixnap.com/about)
- [IaaS Solutions](https://phoenixnap.com/company/iaas-provider)
- [Customer Experience](https://phoenixnap.com/company/customer-experience)
- [Platform](https://phoenixnap.com/cloud-services/platform)
- [Schedule Virtual Tour](https://phoenixnap.com/phoenix-data-center-virtual-tour)
- [Open Source Community](https://phoenixnap.com/company/open-source-community)
- [Resource Library](https://phoenixnap.com/company/resource-library)
- [Press](https://phoenixnap.com/company/press)
- [Events](https://phoenixnap.com/company/it-events)
- [Careers](https://techjobs.dev/jobs/)
- [Promotions](https://phoenixnap.com/promotions)
- [Contact Us](https://phoenixnap.com/contact-us)
- [Legal](https://phoenixnap.com/cs/legal/)
- [Privacy Policy](https://phoenixnap.com/infrastructure-solutions/legal-it/eu-u-s-data-privacy-framework-program-eu-u-s-dpf-compliant-privacy-policy)
- [Terms of Use](https://phoenixnap.com/cs/legal/aup.html)
- [DMCA](https://phoenixnap.com/cs/legal/dmca.html)
- [GDPR](https://phoenixnap.com/gdpr)
- [Sitemap](https://phoenixnap.com/sitemap)
- [Blog](https://phoenixnap.com/blog)
- [Resources](https://phoenixnap.com/company/resource-library)
- [Knowledge Base](https://phoenixnap.com/kb)
- [IT Glossary](https://phoenixnap.com/glossary)
- [GitHub](https://github.com/phoenixnap)
- [RFP Template](https://phoenixnap.com/company/it-resources/data-center-rfp-template)
Ā© 2025 phoenixNAP \| Global IT Services. All Rights Reserved. |
| Readable Markdown | [Home](https://phoenixnap.com/) Ā» [KB](https://phoenixnap.com/kb/) Ā» [SysAdmin](https://phoenixnap.com/kb/category/sysadmin) Ā» Git Revert Commit: How to Undo Last Commit

Topics:
[Git](https://phoenixnap.com/kb/what-is-git) is a popular project tracking application. As a project progresses through different revisions, those revisions are published as a [commit](https://phoenixnap.com/kb/git-commit). A commit represents a checkpoint, where a copy of the project is saved at a specific point. **This guide shows you how to undo the last commit in git.**  Prerequisites An existing project in Git Access to a terminal window/command line **Note:** If you wish to undo a commit to correct an error in the commit message, there is a better way to do it. Learn how to [change a Git commit message](https://phoenixnap.com/kb/git-change-commit-message). How to Revert Commit Git offers many features to manage your project from different historical commits. You can view and revert a previous commit, either published or unpublished. Read on to learn how to identify and revert a published commit. Also, if you want to learn more about Git, check out our article on [how does Git work](https://phoenixnap.com/kb/how-git-works). Identifying the Commit A hash is an alphanumeric code that identifies each commit. Enter the following command to display a commit hash: The hash is necessary to display or manage a specific commit.  To analyze the status of your project from a previous commit, use the checkout command: When using a hash with a Git command, there is no need to type it in its entirety. The first few unique characters are enough for Git to identify an entry accurately. **Note:** Find out how to use [Git checkout tags](https://phoenixnap.com/kb/git-checkout-tag) and why they are useful for your development project. Git Revert: Reverting the Last Git Commit Once a commit is uploaded to the server, it creates a more permanent project log. It is not advisable to use **reset** in this case as other developers may have retrieved the updated project already. Deleting updates from one system may cause conflicts with other team members. Instead, use the **revert** command: Make sure to enter the code for the hash you want to revert to. The system asks you to enter a specific commit message for the changes the **revert** command is going to perform.  This action creates a new commit based on the one you specified, with a **`revert`** tag. This acts as a log, showing that the commit was published and then reverted (instead of pretending it never happened). **Note:** Learn how to use [Git cherry-pick](https://phoenixnap.com/kb/git-cherry-pick) to select and apply a single commit from one branch to another. Git Reset: Revert Unpublished Commits An **unpublished commit** is an update committed in Git but that has not been uploaded to a server. To reset to a previous commit, before any changes were made: This command wipes the slate clean back to the previous commit. Any changes you made will be lost after using the [reset --hard command](https://phoenixnap.com/kb/git-reset-hard). If you want to preserve your work, you can use [Git stash](https://phoenixnap.com/kb/git-stash): The **`stash`** command saves the work you did, and **`stash pop`** retrieves those changes after the reset. Alternately you can use the following: This command resets the commit history, but it leaves your working directory and staging index as-is. **Note:** Git stash allows users to save their uncommitted files and work in progress to a local stash. Learn how to [Git stash specific files](https://phoenixnap.com/kb/git-stash-specific-files). Git Amend: Modify the Last Commit To modify the most recent commit, use the **`git commit --amend`** command. This command replaces the last commit with the amended commit without altering the snapshot. The **`--amend`** flag is usually used to fix minor mistakes. For instance, you want to commit a couple of files in a single snapshot but forget to add one of the files before committing. This issue is easily solved using the **`--amend`** option. First, you add the missing file using: Then, run the command: The **`--no-edit`** option amends the commit without changing the commit message. Conclusion You now know how to use the **`revert`** and **`reset`** commands to undo changes and revert to a previous commit. Additionally, you have learned how to check the status of your current commit. Remember not to use **`reset`** for published commits as it may lead to version conflicts. Was this article helpful? YesNo |
| Shard | 39 (laksa) |
| Root Hash | 8557101678125738839 |
| Unparsed URL | com,phoenixnap!/kb/git-revert-last-commit s443 |