🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 23 (from laksa175)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
2 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead
Last Crawled2026-04-08 14:47:55 (2 days ago)
First Indexed2019-03-04 19:03:32 (7 years ago)
HTTP Status Code200
Meta TitleDon't git revert that last commit, git reset instead | TheServerSide
Meta DescriptionDo you want to reverse a change in your code and think you need to git revert the last commit? For better version control, the best option is almost always git reset.
Meta Canonicalnull
Boilerpipe Text
If you git revert the last commit, you're doing version control wrong. Use git reset --hard instead. It's the choice that makes sense in most scenarios. Don't git revert the last commit If you do feel the need to git revert the last commit, my first question would simply be, "Why?" Was there something in the previous commit you didn't like? Did your source code go in the wrong direction and you simply want to start over? If that's the case, a git revert is the wrong thing to do. You need to do a git reset , not a revert. Here's why it's better to reset, not revert to the last commit. First, when you git reset the last commit, the ID of the bad commit isn't pushed to any remote repository. With a reset, there won't be record of the bad commit on GitHub or Bitbucket . Your local reflog will still track it so it's locally recoverable, but there will be no record of the commit in the team repository. Git reset previous commits The other nice thing that happens when you git reset the last commit is that no new commits are created. The HEAD pointer simply moves back a slot and when you look at the branch history, it's as though the bad commit never happened. Contrast that against git revert . When you git revert the last commit, not only does the full commit history remain intact, but a new commit is created. When you git revert the last commit and push your changes to a shared repository such as GitHub, fellow developers will see three separate commits -- all with unique commit IDs. And to further confuse matters, the first and the third commits will be exactly the same in terms of content. Only the second commit will contain the mistakes. When you git revert the last commit, you complicate the commit history. The reset command eliminates this confusion. TechTarget When you git revert the last commit, it stays in your history and even gets pushed to a remote repository like GitHub or GitLab. Git reset --hard vs. --soft There are other benefits to be reaped when you git reset the last commit. With this method, you can specify either a hard or soft option. When you git reset --hard the last commit, not only does the head move back, but the state of all of the files in your working directory are reset as well. The git reset --hard option would provide the same workspace and index behavior you would see when you git revert the last commit, without all of the associated complications. However, if you git reset --soft , the head will move back to a point at a prior commit, but none of the files in the working directory will change. That means you don't have to scrap all of your changes, and can pick up from where you left off without the last commit you were unhappy with hanging around like a bad odor. How to properly undo the last git commit Trying to undo a mistake with a git revert on the last commit is simply the wrong approach. Because the names sound similar, many people confuse and conflate the Git revert and reset commands. The git revert command is intended to pull the isolated changes made within a previous commit -- with surgical precision -- out of the current code base. A popular tutorial on TheServerSide demonstrates exactly how it works when you git reset a commit, and the behavior of the command is not what people expect. The git reset --hard command is much easier to understand because it does exactly what people expect it to do -- it resets everything back to the way it was in a prior commit . If you want to reset your workspace and dispose of the last commit, use the git reset command. Trying to git revert the last commit is typically the wrong approach.
Markdown
[![](https://cdn.ttgtmedia.com/rms/ux/responsive/img/tss_logo_mobile.png)](https://www.theserverside.com/) [![TheServerSide](https://cdn.ttgtmedia.com/rms/ux/responsive/img/tss_logo.png) ![TheServerSide](https://cdn.ttgtmedia.com/rms/ux/responsive/img/tss_logo.png)](https://www.theserverside.com/) [![TechTarget](https://cdn.ttgtmedia.com/rms/ux/responsive/img/tss_tt_logo.png)](https://www.techtarget.com/) [Sign-up now. Start my free, unlimited access.](https://www.theserverside.com/login?fromURL=https%3A%2F%2Fwww.theserverside.com%2Fvideo%2FDont-git-revert-that-last-commit-git-reset-instead) [Login](https://www.theserverside.com/login?fromURL=https%3A%2F%2Fwww.theserverside.com%2Fvideo%2FDont-git-revert-that-last-commit-git-reset-instead) [Register](https://www.theserverside.com/register?fromURL=https%3A%2F%2Fwww.theserverside.com%2Fvideo%2FDont-git-revert-that-last-commit-git-reset-instead) [Informa TechTarget](https://www.informatechtarget.com/) [Explore the Network](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [App Architecture](https://www.techtarget.com/searchapparchitecture/) - [Software Quality](https://www.techtarget.com/searchsoftwarequality/) - [Cloud Computing](https://www.techtarget.com/searchcloudcomputing/) - [Security](https://www.techtarget.com/searchsecurity/) - [AWS](https://www.techtarget.com/searchaws/) [An Informa TechTarget Publication](https://www.informatechtarget.com/) [Explore our brands](https://www.informatechtarget.com/our-brands) [RSS](https://www.theserverside.com/rss) - - [Core Java](https://www.theserverside.com/resources/Core-Java-APIs-and-programming-techniques) - [DevOps](https://www.theserverside.com/resources/DevOps-driven-cloud-native-app-development) - [More Topics](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Development](https://www.theserverside.com/resources/Software-development-best-practices-and-processes) - [Frameworks](https://www.theserverside.com/resources/Front-end-back-end-and-middle-tier-frameworks) - [Skills and career](https://www.theserverside.com/resources/Professional-skills-development-and-career-advice) - [Tools](https://www.theserverside.com/resources/Development-tools-for-continuous-software-delivery) [Other Content](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Videos](https://www.theserverside.com/videos) - [Definitions](https://www.theserverside.com/definitions) - [Webinars](https://www.theserverside.com/webinars) - [Sponsored Sites](https://www.theserverside.com/sponsored_communities) - [More](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Answers](https://www.theserverside.com/answers) - [Features](https://www.theserverside.com/features) - [Opinions](https://www.theserverside.com/opinions) - [Quizzes](https://www.theserverside.com/quizzes) - [Tech Accelerators](https://www.theserverside.com/techaccelerators) - [Tips](https://www.theserverside.com/tips) - [Tutorials](https://www.theserverside.com/tutorials) ### [Essential Guide](https://www.theserverside.com/guides) Browse Sections - Getting started with Git - [IT pros weigh Git version control against the competition](https://www.techtarget.com/searchsoftwarequality/feature/IT-pros-weigh-Git-version-control-against-the-competition) - [Step-by-step guide: How to install Git on Windows desktop computers](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Step-by-step-guide-to-install-Git-on-Windows-desktop-computers) - [5 basic Git commands developers must master: Tutorial with examples](https://www.theserverside.com/tutorial/Five-basic-Git-commands-every-beginner-needs-to-know) - [How not to write a Git commit message](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-not-to-write-a-Git-commit-message) - [How to set Notepad++ as the default Git editor for commits instead of Vim](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-set-Notepad-as-the-default-Git-editor-for-commits-instead-of-Vim) - Git and Github - [Git vs. GitHub: What's the difference?](https://www.theserverside.com/video/Git-vs-GitHub-What-is-the-difference-between-them) - [Microsoft-GitHub acquisition shakes up DevOps market](https://www.techtarget.com/searchitoperations/news/252442473/Microsoft-GitHub-acquisition-shakes-up-DevOps-market) - [Want a private GitHub repository? It comes with a catch](https://www.theserverside.com/feature/Want-a-private-GitHub-repository-It-comes-with-a-catch) - [How to Git started and use the Github Desktop app tool](https://www.theserverside.com/video/Test-Git-command-basics-on-the-GitHub-Desktop-app) - [Tough sample GitHub interview questions and answers for job candidates](https://www.theserverside.com/video/Tough-sample-Git-and-GitHub-interview-questions-and-answers) - Fix bad mistakes with Git - [How to revert a Git commit: A simple undo changes example](https://www.theserverside.com/tutorial/How-to-git-revert-a-commit-A-simple-undo-changes-example) - [A Git reset hard example: An easy way to undo local commits and shift head](https://www.theserverside.com/video/How-to-use-the-git-reset-hard-command-to-change-a-commit-history) - [Don't Git revert that last commit, Git reset instead](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Learn to Git cherry-pick a commit with this easy example](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Need-to-git-cherry-pick-a-commit-Heres-an-example-how) - [How to 'Git cherry-pick' from another branch to your own](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-git-cherry-pick-from-another-branch-to-your-own) - Git integration with Jenkins - [Jenkins Git integration: GitHub pull request via the Git plugin](https://www.theserverside.com/tutorial/Attain-Jenkins-Git-integration-with-a-GitHub-pull-request) - [How to use the Jenkins Git Plugin: Tips and tricks](https://www.theserverside.com/video/Tips-and-tricks-on-how-to-use-Jenkins-Git-Plugin) - [Jenkins Git environment variables list: A working shell script example](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Complete-Jenkins-Git-environment-variables-list-for-batch-jobs-and-shell-script-builds) - [Use the Jenkins OAuth plug-in to securely pull from GitHub](https://www.theserverside.com/tutorial/Use-the-Jenkins-OAuth-plug-in-to-securely-pull-from-GitHub) - [Tough sample GitHub interview questions and answers for job candidates](https://www.theserverside.com/video/Tough-sample-Git-and-GitHub-interview-questions-and-answers) - Where Git fits in your distributed version control system tool belt - [Follow these Git commit message guidelines](https://www.theserverside.com/video/Follow-these-git-commit-message-guidelines) - [Where system, global and local Windows Git config files are saved](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Where-system-global-and-local-Windows-Git-config-files-are-saved) - [How Atomist's Rod Johnson works with pull requests](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-Atomists-Rod-Johnson-works-with-pull-requests) - [Five ways to fix Git's 'fatal: repository not found' error](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Five-ways-to-fix-Gits-fatal-repository-not-found-error) - [10 Git quiz questions to test your distributed version control skills](https://www.theserverside.com/quiz/Prove-your-DVCS-IQ-with-our-Git-quiz-for-beginners) This content is part of the Essential Guide: [Master Git basics and branch into DVCS](https://www.theserverside.com/essentialguide/Master-Git-basics-and-branch-into-DVCS) # Don't git revert that last commit, git reset instead By - [Cameron McKenzie](https://www.techtarget.com/contributor/Cameron-McKenzie), TechTarget Published: 26 Feb 2019 Related Videos - [Undo and revert pushed Git commits](https://www.theserverside.com/video/Undo-and-revert-pushed-Git-commits) - [![A git reset hard example: An easy way to undo local commits and shift head](https://i.ytimg.com/vi/8vCO_CQ4juQ/default.jpg)](https://www.theserverside.com/video/How-to-use-the-git-reset-hard-command-to-change-a-commit-history) [A git reset hard example: An easy way to undo local commits and shift head](https://www.theserverside.com/video/How-to-use-the-git-reset-hard-command-to-change-a-commit-history) - [![Full Git and GitHub tutorial for beginners](https://i.ytimg.com/vi/l2yrJtwoC_E/default.jpg)](https://www.theserverside.com/video/Full-Git-and-GitHub-tutorial-for-beginners) [Full Git and GitHub tutorial for beginners](https://www.theserverside.com/video/Full-Git-and-GitHub-tutorial-for-beginners) - [![Simple git stash example](https://i.ytimg.com/vi/urSlkC-6lZE/default.jpg)](https://www.theserverside.com/video/An-example-of-how-to-use-the-git-stash-command) [Simple git stash example](https://www.theserverside.com/video/An-example-of-how-to-use-the-git-stash-command) - [View All Videos](https://www.theserverside.com/videos) [View All Videos](https://www.theserverside.com/videos) - Share this item with your network: If you git revert the last commit, you're doing version control wrong. Use git reset --hard instead. It's the choice that makes sense in most scenarios. ## Don't git revert the last commit If you do feel the need to git revert the last commit, my first question would simply be, "Why?" Was there something in the previous commit you didn't like? Did your [source code](https://www.techtarget.com/searchapparchitecture/definition/source-code) go in the wrong direction and you simply want to start over? If that's the case, a git revert is the wrong thing to do. You need to do a git reset, not a revert. Here's why it's better to reset, not revert to the last commit. First, when you git reset the last commit, the ID of the bad commit isn't pushed to any remote repository. With a reset, there won't be record of the bad commit on [GitHub or Bitbucket](https://www.techtarget.com/searchitoperations/tutorial/Boost-DevOps-cred-with-script-management-in-Git-version-control). Your local reflog will still track it so it's locally recoverable, but there will be no record of the commit in the team repository. ## Git reset previous commits The other nice thing that happens when you git reset the last commit is that no new commits are created. The HEAD pointer simply moves back a slot and when you look at the branch history, it's as though the bad commit never happened. Contrast that against git revert. When you git revert the last commit, not only does the full commit history remain intact, but a new commit is created. When you git revert the last commit and push your changes to a shared repository such as GitHub, fellow developers will see three separate commits -- all with unique commit IDs. And to further confuse matters, the first and the third commits will be exactly the same in terms of content. Only the second commit will contain the mistakes. When you git revert the last commit, you complicate the commit history. The reset command eliminates this confusion. ![git revert last commit](https://www.theserverside.com/rms/editorial/22519_TSS_Git-revert-last-commit_half_column_mobile.png) TechTarget When you git revert the last commit, it stays in your history and even gets pushed to a remote repository like GitHub or GitLab. ## Git reset --hard vs. --soft There are other benefits to be reaped when you git reset the last commit. With this method, you can specify either a *hard* or *soft* option. When you git reset --hard the last commit, not only does the head move back, but the state of all of the files in your working directory are reset as well. The git reset --hard option would provide the same workspace and index behavior you would see when you git revert the last commit, without all of the associated complications. However, if you git reset --soft, the head will move back to a point at a prior commit, but none of the files in the working directory will change. That means you don't have to scrap all of your changes, and can pick up from where you left off without the last commit you were unhappy with hanging around like a bad odor. ## How to properly undo the last git commit > If you want to reset your workspace and dispose of the last commit, use the git reset command. Trying to undo a mistake with a git revert on the last commit is simply the wrong approach. Because the names sound similar, many people confuse and conflate the Git *revert* and *reset* commands. The git revert command is intended to pull the isolated changes made within a previous commit -- with surgical precision -- out of the current code base. A [popular tutorial](https://www.theserverside.com/video/How-to-use-the-git-reset-hard-command-to-change-a-commit-history) on TheServerSide demonstrates exactly how it works when you git reset a commit, and the behavior of the command is not what people expect. The git reset --hard command is much easier to understand because it does exactly what people expect it to do -- it resets everything back to the way it was [in a prior commit](https://git-scm.com/docs/git-reset). If you want to reset your workspace and dispose of the last commit, use the git reset command. Trying to git revert the last commit is typically the wrong approach. Latest TechTarget resources - [Application Architecture](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Software Quality](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Cloud Computing](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [Security](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) - [AWS](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) [Search App Architecture](https://www.techtarget.com/searchapparchitecture/) - [KubeCon EU 2026: Infrastructure catches up to AI](https://www.techtarget.com/searchapparchitecture/opinion/KubeCon-EU-2026-Infrastructure-catches-up-to-AI) AI is reshaping infrastructure demands. At KubeCon EU 2026, vendors focused on Kubernetes abstraction, GPU management and ... - [KubeCon EU 2026: AI tightens the dev-prod loop](https://www.techtarget.com/searchapparchitecture/opinion/KubeCon-EU-2026-AI-tightens-the-dev-prod-loop) AI is reshaping platform engineering. At KubeCon EU 2026, vendors showcased autonomous troubleshooting, observability-driven ... - [How to build lightning-fast Quarkus native executables](https://www.techtarget.com/searchapparchitecture/tip/How-to-build-lightning-fast-Quarkus-native-executables) Want to build cloud-native Java apps in Java versus Go and Rust? This step-by-step tutorial shows how to create native ... [Search Software Quality](https://www.techtarget.com/searchsoftwarequality/) - [Harness Artifact Registry strengthens supply chain governance](https://www.techtarget.com/searchsoftwarequality/news/366639489/Harness-Artifact-Registry-strengthens-supply-chain-governance) Harness makes its artifact registry generally available beyond early preview customers, with a security twist that could ... - [AWS Kiro 'user error' reflects common AI coding review gap](https://www.techtarget.com/searchsoftwarequality/news/366639129/AWS-Kiro-user-error-reflects-common-AI-coding-review-gap) Even internal AWS Kiro users haven't always peer-reviewed AI code output, as evidenced by a reported December outage that ... - [AWS AI IDE, AgentCore throw down gauntlets for Microsoft](https://www.techtarget.com/searchsoftwarequality/news/366635669/AWS-AI-IDE-AgentCore-throw-down-gauntlets-for-Microsoft) Kiro emerges as a significant alternative to GitHub Copilot agents, while AWS AgentCore updates square off against Agent 365 in ... [Search Cloud Computing](https://www.techtarget.com/searchcloudcomputing/) - [Is your cloud storage ready for AI workloads?](https://www.techtarget.com/searchcloudcomputing/tip/Is-your-cloud-storage-ready-for-AI-workloads) Cloud storage design directly impacts AI performance, scalability and cost. Learn how to choose the right storage types, optimize... - [State of the Cloud report shows shift from cost-cutting to value](https://www.techtarget.com/searchcloudcomputing/feature/State-of-the-Cloud-report-shows-shift-from-cost-cutting-to-value) The CTO of Flexera shares his expert insights into the 2026 State of the Cloud Report’s findings and highlights a pivotal shift ... - [Top 8 benefits of hybrid cloud for business](https://www.techtarget.com/searchcloudcomputing/tip/Top-5-benefits-of-hybrid-cloud) Why choose between public cloud and private systems when you can have both? With hybrid cloud, enterprises can address workload ... [Search Security](https://www.techtarget.com/searchsecurity/) - [Meaningful metrics demonstrate the value of cyber-resiliency](https://www.techtarget.com/searchsecurity/tip/Meaningful-metrics-demonstrate-the-value-of-cyber-resiliency) Cyber-resilience metrics translate raw technical performance into real business outcomes. The right analytics can enhance more ... - [What to know about red team testing and the law](https://www.techtarget.com/searchsecurity/feature/What-to-know-about-red-team-testing-and-the-law) Red teaming isn't just about finding flaws in cyberdefenses. There are important legal implications that deserve careful ... - [News brief: Iran cyberattacks escalate, U.S. targets named](https://www.techtarget.com/searchsecurity/news/366641212/News-brief-Iran-cyberattacks-escalate-US-targets-named) Check out the latest security news from the Informa TechTarget team. [Search AWS](https://www.techtarget.com/searchaws/) - [Compare Datadog vs. New Relic for IT monitoring in 2024](https://www.techtarget.com/searchaws/tip/Compare-CloudWatch-vs-Datadog-and-New-Relic-for-AWS-monitoring) Compare Datadog vs. New Relic capabilities including alerts, log management, incident management and more. Learn which tool is ... - [AWS Control Tower aims to simplify multi-account management](https://www.techtarget.com/searchaws/tip/AWS-Control-Tower-aims-to-simplify-multi-account-management) Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates ... - [Break down the Amazon EKS pricing model](https://www.techtarget.com/searchaws/tip/Compare-EKS-pricing-to-other-managed-Kubernetes-services) There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service ... - Follow: - [About Us](https://www.informatechtarget.com/editorial/) - [Editorial Ethics Policy](https://www.techtarget.com/techtarget-editorial-ethics-policy) - [Meet The Editors](https://www.techtarget.com/editorial-contacts) - [Contact Us](https://www.informatechtarget.com/contact-us/) - [Advertisers](https://www.informatechtarget.com/for-advertisers/) - [Partner with Us](https://www.informatechtarget.com/partner-with-us/) - [Media Kit](https://www.informatechtarget.com/wp-content/uploads/2023/09/TechTarget-Media-Kit-Handout-with-product-descriptions.pdf) - [Corporate Site](https://www.informatechtarget.com/) - [Contributors](https://www.theserverside.com/contributors) - [Reprints](https://licensing.ygsgroup.com/ygspublishersolutions/) - [Answers](https://www.theserverside.com/answers) - [Definitions](https://www.theserverside.com/definitions) - [E-Products](https://www.theserverside.com/eproducts) - [Events](https://www.brighttalk.com/summits) - [Features](https://www.theserverside.com/features) - [Guides](https://www.theserverside.com/guides) - [Opinions](https://www.theserverside.com/opinions) - [Photo Stories](https://www.theserverside.com/photostories) - [Quizzes](https://www.theserverside.com/quizzes) - [Tips](https://www.theserverside.com/tips) - [Tutorials](https://www.theserverside.com/tutorials) - [Videos](https://www.theserverside.com/videos) [©2026 TechTarget](https://www.informatechtarget.com/terms-of-use), Inc. d/b/a Informa TechTarget. All Rights Reserved. [Privacy Policy](https://www.informatechtarget.com/privacy-policy/) [Cookie Preferences](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) [Cookie Preferences](https://www.theserverside.com/video/Dont-git-revert-that-last-commit-git-reset-instead) [Do Not Sell or Share My Personal Information](https://techtarget.zendesk.com/hc/en-us/requests/new?ticket_form_id=360004852434) Close ![](https://go.techtarget.com/clicktrack-r/activity/activity.gif?activityTypeId=16&t=365532356&t2=314887&t3=450295813&t4=315044&a=2026-04-07%2016:48:18&g=252458347&c=normal&auid=61287b01-a0de-4f7a-94b3-f9916c03f49a&r=830448)
Readable Markdown
If you git revert the last commit, you're doing version control wrong. Use git reset --hard instead. It's the choice that makes sense in most scenarios. ## Don't git revert the last commit If you do feel the need to git revert the last commit, my first question would simply be, "Why?" Was there something in the previous commit you didn't like? Did your [source code](https://www.techtarget.com/searchapparchitecture/definition/source-code) go in the wrong direction and you simply want to start over? If that's the case, a git revert is the wrong thing to do. You need to do a git reset, not a revert. Here's why it's better to reset, not revert to the last commit. First, when you git reset the last commit, the ID of the bad commit isn't pushed to any remote repository. With a reset, there won't be record of the bad commit on [GitHub or Bitbucket](https://www.techtarget.com/searchitoperations/tutorial/Boost-DevOps-cred-with-script-management-in-Git-version-control). Your local reflog will still track it so it's locally recoverable, but there will be no record of the commit in the team repository. ## Git reset previous commits The other nice thing that happens when you git reset the last commit is that no new commits are created. The HEAD pointer simply moves back a slot and when you look at the branch history, it's as though the bad commit never happened. Contrast that against git revert. When you git revert the last commit, not only does the full commit history remain intact, but a new commit is created. When you git revert the last commit and push your changes to a shared repository such as GitHub, fellow developers will see three separate commits -- all with unique commit IDs. And to further confuse matters, the first and the third commits will be exactly the same in terms of content. Only the second commit will contain the mistakes. When you git revert the last commit, you complicate the commit history. The reset command eliminates this confusion. ![git revert last commit](https://www.theserverside.com/rms/editorial/22519_TSS_Git-revert-last-commit_half_column_mobile.png) TechTarget When you git revert the last commit, it stays in your history and even gets pushed to a remote repository like GitHub or GitLab. ## Git reset --hard vs. --soft There are other benefits to be reaped when you git reset the last commit. With this method, you can specify either a *hard* or *soft* option. When you git reset --hard the last commit, not only does the head move back, but the state of all of the files in your working directory are reset as well. The git reset --hard option would provide the same workspace and index behavior you would see when you git revert the last commit, without all of the associated complications. However, if you git reset --soft, the head will move back to a point at a prior commit, but none of the files in the working directory will change. That means you don't have to scrap all of your changes, and can pick up from where you left off without the last commit you were unhappy with hanging around like a bad odor. ## How to properly undo the last git commit Trying to undo a mistake with a git revert on the last commit is simply the wrong approach. Because the names sound similar, many people confuse and conflate the Git *revert* and *reset* commands. The git revert command is intended to pull the isolated changes made within a previous commit -- with surgical precision -- out of the current code base. A [popular tutorial](https://www.theserverside.com/video/How-to-use-the-git-reset-hard-command-to-change-a-commit-history) on TheServerSide demonstrates exactly how it works when you git reset a commit, and the behavior of the command is not what people expect. The git reset --hard command is much easier to understand because it does exactly what people expect it to do -- it resets everything back to the way it was [in a prior commit](https://git-scm.com/docs/git-reset). If you want to reset your workspace and dispose of the last commit, use the git reset command. Trying to git revert the last commit is typically the wrong approach.
Shard23 (laksa)
Root Hash7434987543936799023
Unparsed URLcom,theserverside!www,/video/Dont-git-revert-that-last-commit-git-reset-instead s443