Skip to main content

Undoing Changes in Git

 

Undoing Changes in Git: A Professional Guide to Reset, Revert, Stash & Cherry-Pick

📅 Published: Feb 2026
⏱️ Estimated Reading Time: 15 minutes
🏷️ Tags: Git Reset, Git Revert, Git Stash, Git Cherry-pick, DevOps



Overview

Mistakes are a normal part of software development.
Git provides powerful tools to undo changes safely, whether you want to discard local edits, undo commits, temporarily save work, or selectively apply changes.

This guide explains Git reset, revert, stash, and cherry-pick in a professional and beginner-friendly way.



Understanding Undo Operations in Git

Undoing changes in Git depends on what you want to undo and where the change exists.

Common Scenarios

  • Undo local file changes

  • Undo committed changes

  • Save unfinished work temporarily

  • Apply specific commits to another branch

Git offers different commands for each scenario.



git reset Explained

git reset moves the HEAD pointer and optionally updates the staging area and working directory.

Types of git reset

ModeAffects Commit HistoryStaging AreaWorking Directory
--softYesNoNo
--mixed (default)YesYesNo
--hardYesYesYes

git reset --soft

Moves HEAD but keeps changes staged.

git reset --soft HEAD~1

Use case:
Modify the last commit message or regroup commits.



git reset --mixed

Unstages changes but keeps files intact.

git reset HEAD~1

Use case:
Re-stage changes differently.



git reset --hard

Completely removes commits and changes.

git reset --hard HEAD~1

⚠️ Warning: This permanently deletes changes.



git revert Explained

git revert creates a new commit that reverses an earlier commit.

git revert <commit-id>

When to Use git revert

  • Undo changes in shared branches

  • Maintain safe commit history

  • Production environments

👉 git revert is preferred in teams.



git reset vs git revert

FeatureResetRevert
History RewriteYesNo
Safe for TeamsNoYes
Creates New CommitNoYes
Best Use CaseLocal cleanupShared branches


git stash Explained

git stash temporarily saves uncommitted changes and cleans the working directory.

git stash

Common Commands

git stash list git stash apply git stash pop

Use Case:

Switch branches without committing unfinished work.



git cherry-pick Explained

git cherry-pick applies a specific commit from one branch to another.

git cherry-pick <commit-id>

Use Case:

  • Apply bug fix to multiple branches

  • Selective commit transfer



Choosing the Right Command

ScenarioRecommended Command
Undo local commitgit reset
Undo shared commitgit revert
Save work temporarilygit stash
Copy specific commitgit cherry-pick

How These Commands Help DevOps Teams

These commands enable:

  • Safe rollback in CI/CD pipelines

  • Controlled production fixes

  • Efficient release management

  • Reduced deployment risks

Hands-on Git recovery workflows are practiced in SKY Tech DevOps programs:
👉 https://devops.trainwithsky.com



Best Practices for Undoing Changes

Best PracticeReason
Avoid --hard on shared branchesPrevent data loss
Use revert for productionSafe history
Check git status before undoAwareness
Backup before risky operationsSafety

Frequently Asked Questions (FAQs)

Is git reset --hard dangerous?

Yes. It permanently deletes changes.


Should I use reset or revert?

Use reset locally, revert in teams.


Does stash save untracked files?

Only with:

git stash -u

Can cherry-pick cause conflicts?

Yes, if changes overlap.


Where can I practice Git recovery scenarios?

Practice safely with real workflows at SKY Tech:
👉 https://devops.trainwithsky.com



Conclusion

Undoing changes in Git is a critical skill for developers and DevOps engineers.
Understanding when and how to use reset, revert, stash, and cherry-pick ensures safer workflows and confident development.



Recommended Next Reads

  • Advanced Git Commands

  • Git Workflow Strategies

  • GitHub Pull Requests & Reviews

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...