Guides
Git Commit सुरक्षितपणे Undo कसे करावे (reset, revert, amend) By Ravindra Bagale , DevOps trainer · LinkedIn · Published: 28 October 2026 · Last updated: 28 October 2026
Local: reset/amend. Shared: git revert. Main वर blind force-push नाही.
English मराठी हिंदी
Friends, undo tools are different knives. Chala mitrano — local reset is fine; shared history needs revert.
मित्रांनो, undo साधने वेगवेगळी सुरी आहेत. Chala mitrano — local reset ठीक; shared history ला revert.
मित्रों, undo औज़ार अलग छुरियाँ हैं। Chala mitrano — local reset ठीक; shared history को revert।
Quick answer
Hold this vertical picture:
Local vs pushed विचारा.
Local: reset/amend.
Shared: revert.
reflog.
status+log.
Language: English · मराठी · हिंदी
Wrong commit? Local or already pushed?
Local only reset or amend
Already on remote git revert
Never blind force Protect shared main
Verify log and status
Undo safely
Accenture shared main वर चुकीचा commit reset ने पुसून टाकू नका — teammates दुखतात.
Why: Local rewrite खाजगी; shared ला नवीन commit.
What: reset, amend, revert.
How: इतरांनी tip pull केली का?
Example 1: Lab with three commits
Type this:
rm -rf /tmp/undo-lab && mkdir -p /tmp/undo-lab && cd /tmp/undo-lab && git init -b main && git config user.email lab@example.com && git config user.name Lab && printf 'a\n' > f && git add f && git commit -m 'c1' && printf 'b\n' >> f && git commit -am 'c2' && printf 'BAD\n' >> f && git commit -am 'c3-bad' && git log --oneline
You will see:
... c3-bad\n... c2\n... c1
What it means: Three commits; c3-bad is the mistake we will undo in different ways.
Example 8: Decision: local vs pushed
Type this:
printf '%s\n' 'LOCAL not pushed: reset or amend OK' 'PUSHED shared: git revert' 'PUSHED solo branch: reset + force-with-lease only if alone'
You will see:
LOCAL not pushed: reset or amend OK\nPUSHED shared: git revert\nPUSHED solo branch: reset + force-with-lease only if alone
What it means: Say this card in Infosys interviews.
soft/mixed/hard HEAD हलवतात; hard worktree पुसते.
Why: Local tip सुरक्षित काढणे.
What: git reset --soft|--mixed|--hard HEAD~1
How: Hard फक्त lab.
Example 2: Soft reset keeps files staged
Type this:
cd /tmp/undo-lab && git reset --soft HEAD~1 && git status -sb && git log --oneline -n 2
You will see:
## main\nM f (or staged changes)\n... c2
What it means: soft moves HEAD back; changes stay staged. Good before re-commit.
Example 3: Restore the bad commit for next demos
Type this:
cd /tmp/undo-lab && git commit -m 'c3-bad' && git log --oneline -n 3
You will see:
... c3-bad\n... c2\n... c1
What it means: Put c3-bad back so mixed and hard demos have a target.
Example 4: Mixed reset unstages
Type this:
cd /tmp/undo-lab && git reset HEAD~1 && git status -sb && git log --oneline -n 2
You will see:
What it means: Default mixed reset: HEAD back, changes unstaged in working tree.
Example 5: Hard reset discards worktree (lab only)
Type this:
cd /tmp/undo-lab && git add -A && git commit -m 'c3-bad' >/dev/null; git reset --hard HEAD~1 && git log --oneline -n 2 && git status -sb
You will see:
What it means: hard deletes the commit and working changes. Dangerous on real work — lab only.
amend tip rewrite; revert undo commit जोडते.
Why: Shared tip सहज rewrite नका.
What: commit --amend; revert HEAD
How: TCS main वर revert.
Example 6: Amend last local commit message
Type this:
cd /tmp/undo-lab && printf 'x\n' >> f && git add f && git commit -m 'typo-msg' && git commit --amend -m 'clear message' && git log --oneline -n 1
You will see:
What it means: amend rewrites the tip commit. Safe only if not pushed yet.
Example 7: Revert creates a new undo commit
Type this:
cd /tmp/undo-lab && printf 'oops\n' >> f && git commit -am 'bad-on-main' && git revert --no-edit HEAD && git log --oneline -n 3
You will see:
... Revert "bad-on-main"\n... bad-on-main\n...
What it means: revert adds a forward commit that undoes changes — safe for shared main.
reflog हरवलेले tip शोधते.
Why: Panic नंतर नकाशा हवा.
What: reflog; status; log
How: Secret असेल तर rotate.
Example 9: Recover a soft-reset tip with reflog
Type this:
cd /tmp/undo-lab && git reflog -n 5
You will see:
HEAD@{0}: ...\nHEAD@{1}: ...
What it means: reflog remembers where HEAD was — recovery map after reset.
Example 10: Do not chmod secrets into history
Type this:
printf '%s\n' 'If a secret was committed: rotate the secret, then rewrite history with team help — do not leave it'
You will see:
If a secret was committed: rotate the secret, then rewrite history with team help — do not leave it
What it means: Undo is not enough for leaked passwords — rotate first.
Example 11: Verify after undo
Type this:
cd /tmp/undo-lab && git status -sb && git log --oneline -n 4
You will see:
What it means: Always status + log after undo tools.
Example 12: Undo card
Type this:
printf '%s\n' '1 local? reset/amend 2 shared? revert 3 verify log 4 never blind force main'
You will see:
1 local? reset/amend 2 shared? revert 3 verify log 4 never blind force main
What it means: Memorize for Flipkart-style service repos.
Ravindra Bagale's Tip
English मराठी हिंदी
On Accenture shared main, prefer git revert. Soft reset and amend stay on your laptop until you push.
Accenture shared main वर git revert पसंत करा. Soft reset आणि amend push पर्यंत laptop वर राहतात.
Accenture shared main पर git revert चुनें। Soft reset और amend push तक लैपटॉप पर रहते हैं।
Q1. Soft vs hard? Soft staged ठेवते; hard worktree पुसते
Q2. Shared main सुरक्षित undo? git revert
Q3. Amend कधी सुरक्षित? Tip push झाले नसेल
Q4. हरवलेले tip? git reflog
Q5. Force-push main? नाही
Q6. Secret commit? आधी rotate, नंतर team सोबत history
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
Mark as read
Local → reset/amend. Shared → revert. Verify.
Did you understand? Let us try it once more.
Live batch madhe shikaycha aahe? Online / offline training with Ravindra Bagale – AWS, DevOps, Data Analytics, Power BI, Cyber Security.
Enquire now → Chat on WhatsApp
Frequently asked questions Soft vs hard reset? Soft keeps changes staged; hard resets the worktree too.
How to undo on shared main? git revert creates a new commit.
When can I amend? When the commit was not pushed, or only you use the branch.
What is reflog for? Finding commits after a reset.
Force-push main? Not without a written team rule.
Secret committed? Rotate the secret, then fix history with the team.
How to Install Nginx on Amazon Linux 2023 (EC2) How to SSH into EC2 from Windows, Mac and Linux How to Launch an EC2 Instance in AWS (Step by Step) How to Install Apache (httpd) on Amazon Linux 2023 EC2 How to Fix Permission denied (publickey) on AWS EC2 How to Open Port 80 and 443 in an EC2 Security Group How to Attach an Elastic IP to an EC2 Instance How to Host a Static Website on EC2 with Nginx How to Connect a GoDaddy Domain to AWS EC2 How to Install a Free SSL Certificate on EC2 (Certbot) How to Install WordPress on AWS EC2 (Amazon Linux 2023) How to Increase EBS Volume Size Without Downtime How to Attach an IAM Role to an EC2 Instance How to Install Docker on Amazon Linux 2023 (EC2) How to Install and Configure AWS CLI (Windows, Mac, Linux) How to Set Up an AWS Billing Alarm and Budget (Free Tier) How to Host a Static Website on Amazon S3 How to Create an IAM User with MFA (Stop Using Root) How to Set Up an Application Load Balancer for Two EC2s How to Create an RDS MySQL Database and Connect from EC2 Your First AWS Lambda Function in Python (Console) How to Install WordPress Plugins and Themes Without FTP Nginx Config Explained: Change Port, Root and Index (AL2023) How to Create a Custom VPC in AWS: Subnets, IGW and Routes AWS VPC CIDR and Subnet Calculation Explained Public vs Private Subnet in AWS: The Route Table Difference How to Block an IP Address or IP Range Using AWS NACL Security Group vs NACL in AWS: Differences with Examples How to Set Up a NAT Gateway for a Private Subnet in AWS How to SSH into a Private EC2 Through a Bastion (Jump) Host 3-Tier Architecture on AWS: Nginx, PHP and MySQL in a VPC What Is Phishing and How to Spot It What Is Ransomware and How to Protect Yourself How to Enable MFA on Google, Microsoft and AWS OWASP Top 10 Explained Simply (2025) What Is SQL Injection and How to Prevent It How to Set Up SPF, DKIM and DMARC for Email How to Harden a Linux Server (Checklist) How to Use Nmap for Basic Network Scanning (Ethical Lab) How to Analyse a Phishing Email Like a SOC Analyst Incident Response Plan for Beginners (First 24 Hours) What Is Malware? Types and How to Protect Yourself How to Set Up a Password Manager (Beginner Guide) EDR vs Antivirus: What’s the Difference What Is SIEM? How SOC Analysts Use It What Is a Data Breach? What to Do If Your Data Was Exposed How Does a Firewall Work? (Beginner Explainer) What Is a VPN and When Should You Use One? Zero Trust Security Explained Simply What Is XSS (Cross-Site Scripting) and How to Prevent It How to Secure Your Home Wi‑Fi Network (Step-by-Step) Vulnerability Management: CVEs, KEV, Patching and Verification Windows Event Logs and Sysmon for Beginner SOC MITRE ATT&CK + Your First Sigma Detection Rule (Defence) Cloud IAM Least Privilege AI Security: Defend Prompt Injection and Data Leakage SBOM, Dependency Risk and Secret Leaks Wireshark Packet Analysis for Beginners (Defender View) Backup and Disaster Recovery: RPO, RTO and Restore Testing Cryptography, TLS, Certificates and PKI in Practice Safe Metasploitable / Vulnerable Home Lab Setup What Is Penetration Testing? (Ethical, Authorised Only) Secure REST APIs with OWASP API Security Top 10 Threat Hunting for Beginners (Defence) Kubernetes Security Basics for Defenders DevSecOps Security Pipeline (SAST, SCA, Secrets) Python for SOC Analysts (Defence Automation) Active Directory Hardening and Monitoring (Defender Guide) Machine Identity Security: Service Accounts, Keys and Workloads STRIDE Threat Modeling Guide for Builders and Defenders Digital Forensics for Beginners: Evidence, Hashes and Timelines OT / ICS Cybersecurity Monitoring Lab (Safe Education) What Is Cloud Security? Beginner’s Guide AWS Security Best Practices Checklist What Is a SOC? What Does a SOC Analyst Do? How to Write a Cybersecurity Incident Report Azure Cloud Security Basics for Beginners Cybersecurity Skills Companies Hire For (2026) 50 Cybersecurity Interview Questions and Answers (Basics) 50 SOC Analyst Interview Questions and Answers 50 Network Security Interview Questions and Answers 50 Cloud / AWS Security Interview Questions and Answers 50 IAM, MFA and Zero Trust Interview Questions and Answers AppSec OWASP Interview Questions (50) — SQLi, XSS, API Linux Security Interview Questions (50) — Hardening & Commands Incident Response Interview Questions (50) — IR / DFIR Beginner Ethical Hacking & Pentest Interview Questions (50) — Concepts Python Scripting for SOC Interview Questions (50) How Android Phone Hacking Happens (Defence Guide) Android Device Cloning Risks and Defence How Android Data Theft Happens — and How to Defend Android Safe App Install and Sideload Risks Android Malware and Spyware: Signs, Remove and Protect Android Banking OTP, SIM Swap and MFA Protection Lost or Stolen Android: Find, Lock and Remote Wipe Android Public Wi‑Fi and Hotspot Risks How iPhone Hacking Happens (Defence Guide) Apple ID and iCloud Takeover Defence iPhone Data Theft Risks and Defence iPhone App, Profile and MDM Risks Stolen or Lost iPhone: Find My and Lockdown Mode iPhone Banking OTP, SIM Swap and MFA Protection Signs Your iPhone May Be Compromised How Windows Laptop Hacking Happens (Defence Guide) Windows Malware and Ransomware Protection Windows Safe Software Install Habits Windows Update and Microsoft Defender Basics Windows Account, MFA and BitLocker Hardening Windows Remote Access: RDP and AnyDesk Risks Windows Data Theft: Browser and USB Defence Windows Laptop Stolen or Infected: Recover Checklist Power BI Desktop vs Service vs Mobile Explained Install Power BI Desktop and Build Your First Report Connect Excel and CSV Files to Power BI Measures vs Calculated Columns in Power BI Power Query vs DAX: What Goes Where What Is DAX? Beginner Guide for Power BI How CALCULATE Works with Filter Context SUM vs SUMX in Power BI DAX Build Your First Power BI Dashboard How to Use Slicers in Power BI Power BI File Types: PBIX, PBIT and PBIDS Connect SQL Server to Power BI (Import vs DirectQuery) Power BI Import vs DirectQuery vs Dual Power BI Fields, Filters and Visualizations Panes Turn Off Auto Date/Time in Power BI DAX Row Context vs Filter Context DAX Context Transition with CALCULATE Using FILTER Inside CALCULATE in DAX DAX ALL, ALLEXCEPT, ALLSELECTED and REMOVEFILTERS DAX RELATED and RELATEDTABLE DAX KEEPFILTERS with CALCULATE DAX IF and SWITCH Measures DAX DIVIDE for Safe Percentages DAX Year-to-Date TOTALYTD and DATESYTD DAX Month-to-Date and Quarter-to-Date DAX Same Period Last Year and YoY DAX Running Totals DAX RANKX DAX Percentage of Total with ALLSELECTED DAX USERELATIONSHIP for Inactive Relationships DAX VAR and RETURN DAX COUNT, COUNTA, DISTINCTCOUNT and COUNTROWS DAX Rolling 12-Month Average DAX CALCULATETABLE vs FILTER Intermediate DAX Patterns in Power BI How to Choose a Chart in Power BI Power BI Matrix Visual Power BI KPI, Card and Scorecard Power BI Report Page Tooltips Power BI Drill-through Pages Power BI Bookmarks and Buttons Power BI Conditional Formatting Power BI Hierarchy and Drill Down Power BI Field Parameters Power BI Report Layout Design Power Query Applied Steps Power Query Data Types Power Query Duplicate vs Reference Star Schema in Power BI Fact and Dimension Tables in Power BI Power BI Relationships: One to Many Power BI Cardinality and Filter Direction Star vs Snowflake Schema in Power BI Composite Models in Power BI Publish a Power BI Report to the Service Power BI Workspaces and Roles Power BI Apps for Sharing Reports Power BI Dashboard vs Report How to Share a Power BI Report Row-Level Security in Power BI What Is DevOps? Beginner Guide DevOps म्हणजे काय? नवशिक्यांसाठी मार्गदर्शक DevOps क्या है? शुरुआती guide Git Basics for DevOps Beginners DevOps नवशिक्यांसाठी Git Basics DevOps शुरुआती के लिए Git Basics Git Branching and Pull Requests for Beginners नवशिक्यांसाठी Git Branching आणि Pull Requests शुरुआती के लिए Git Branching और Pull Requests Install Docker on EC2 for Beginners नवशिक्यांसाठी EC2 वर Docker Install शुरुआती के लिए EC2 पर Docker Install Your First Dockerfile for Beginners नवशिक्यांसाठी पहिला Dockerfile शुरुआती के लिए पहला Dockerfile Docker Compose for Beginners नवशिक्यांसाठी Docker Compose शुरुआती के लिए Docker Compose Your First GitHub Actions Pipeline तुमची पहिली GitHub Actions Pipeline आपकी पहली GitHub Actions Pipeline Jenkins Pipeline for Beginners नवशिक्यांसाठी Jenkins Pipeline शुरुआती के लिए Jenkins Pipeline Your First Ansible Playbook तुमचा पहिला Ansible Playbook आपका पहला Ansible Playbook Terraform First Apply for Beginners नवशिक्यांसाठी Terraform First Apply शुरुआती के लिए Terraform First Apply DevOps Roadmap 2026: What to Learn in Order DevOps Roadmap 2026: काय शिकावं आणि कोणत्या क्रमाने DevOps Roadmap 2026: क्या सीखें और किस क्रम में DevOps vs SRE vs Platform Engineer: Which Role Fits You? DevOps vs SRE vs Platform Engineer: तुमच्यासाठी कोणती भूमिका? DevOps vs SRE vs Platform Engineer: आपके लिए कौन सी भूमिका? DevOps Engineer Resume Skills Checklist (Fresher and 2+ Years) DevOps Engineer Resume Skills Checklist (Fresher आणि 2+ Years) DevOps Engineer Resume Skills Checklist (Fresher और 2+ Years) How to Prepare for a DevOps Interview in 30 Days DevOps Interview साठी ३० दिवसांत तयारी कशी करायची DevOps Interview की तैयारी 30 दिनों में कैसे करें Linux Commands Every DevOps Engineer Uses Daily दररोज DevOps Engineer वापरतो ती Linux Commands हर दिन DevOps Engineer जो Linux Commands इस्तेमाल करता है How to Write a Bash Script for Server Health and Disk Alerts Server Health आणि Disk Alerts साठी Bash Script कशी लिहावी Server Health और Disk Alerts के लिए Bash Script कैसे लिखें Cron Jobs Explained: Schedule Backups and Log Cleanup Cron Jobs समजावून: Backups आणि Log Cleanup शेड्यूल करा Cron Jobs समझाया: Backups और Log Cleanup शेड्यूल करें How to Troubleshoot with systemctl and journalctl systemctl आणि journalctl ने Troubleshooting कशी करायची systemctl और journalctl से Troubleshooting कैसे करें How to Resolve Git Merge Conflicts Step by Step Git Merge Conflicts Step by Step कशी सोडवायच्या Git Merge Conflicts Step by Step कैसे सुलझाएँ Git Rebase vs Merge: When to Use Which (With Examples) Git Rebase vs Merge: कधी काय वापरायचे (उदाहरणांसह) Git Rebase vs Merge: कब क्या इस्तेमाल करें (उदाहरणों के साथ) How to Undo a Git Commit Safely (reset, revert, amend) Git Commit सुरक्षित Undo कैसे करें (reset, revert, amend) How to Shrink a Docker Image with Multi-stage Builds Multi-stage Builds ने Docker Image कशी लहान करायची Multi-stage Builds से Docker Image कैसे छोटा करें Docker Volumes vs Bind Mounts Explained with Examples Docker Volumes vs Bind Mounts उदाहरणांसह Docker Volumes vs Bind Mounts उदाहरणों के साथ How to Debug a Running Docker Container (logs, exec, inspect) Running Docker Container Debug कसे करावे (logs, exec, inspect) Running Docker Container Debug कैसे करें (logs, exec, inspect) Docker Networking Explained: Bridge, Host and Custom Networks Docker Networking: Bridge, Host आणि Custom Networks Docker Networking: Bridge, Host और Custom Networks How to Set Up CI/CD for a React App on AWS React App साठी AWS वर CI/CD कसे सेटअप करावे React App के लिए AWS पर CI/CD कैसे सेटअप करें How to Deploy a Node.js App to EC2 with GitHub Actions GitHub Actions ने Node.js App EC2 वर Deploy कसे करावे GitHub Actions से Node.js App EC2 पर Deploy कैसे करें How to Build and Push a Docker Image from Jenkins Jenkins मधून Docker Image Build आणि Push कसे करावे Jenkins से Docker Image Build और Push कैसे करें GitLab CI Pipeline for Beginners (.gitlab-ci.yml) GitLab CI Pipeline Beginners साठी (.gitlab-ci.yml) GitLab CI Pipeline Beginners के लिए (.gitlab-ci.yml) How to Add a Manual Approval Gate Before Production Deploy Production Deploy आधी Manual Approval Gate कसे जोडावे Production Deploy से पहले Manual Approval Gate कैसे जोड़ें How to Deploy Your First App on Kubernetes (Deployment + Service) Kubernetes वर पहिली App Deploy कशी करावी (Deployment + Service) Kubernetes पर पहली App Deploy कैसे करें (Deployment + Service) How to Install kubectl and kind (or minikube) on Linux, Mac and Windows Linux, Mac, Windows वर kubectl आणि kind (किंवा minikube) Install Linux, Mac, Windows पर kubectl और kind (या minikube) Install Kubernetes ConfigMaps and Secrets Explained with Examples Kubernetes ConfigMaps आणि Secrets उदाहरणांसह Kubernetes ConfigMaps और Secrets उदाहरणों के साथ How to Set Up Nginx Ingress on Kubernetes Kubernetes वर Nginx Ingress कसे सेटअप करावे Kubernetes पर Nginx Ingress कैसे सेटअप करें Data Science vs Data Analytics vs BI Explained Python for Data Science: Beginner First Steps Install Python 3, venv and Jupyter for Data Science pandas DataFrame for Beginners: Series vs DataFrame pandas read_csv and read_excel for Beginners pandas Filter Rows and Columns (Select, Boolean, Sort) pandas groupby and Aggregation for Beginners Handle Missing Values in pandas (NaN, dropna, fillna) Exploratory Data Analysis (EDA) in Python with pandas matplotlib and seaborn: First Charts for Storytelling Data Science vs Data Analytics vs BI — समजावून सांगितलं Data Science vs Data Analytics vs BI समझाया Data Science साठी Python: नवशिक्यांची पहिली पावलं Data Science के लिए Python: शुरुआती first steps Data Science साठी Python 3, venv आणि Jupyter install Data Science के लिए Python 3, venv और Jupyter install pandas DataFrame नवशिक्यांसाठी: Series vs DataFrame pandas DataFrame शुरुआती: Series vs DataFrame pandas read_csv आणि read_excel नवशिक्यांसाठी pandas read_csv और read_excel शुरुआती pandas मध्ये rows आणि columns filter (select, boolean, sort) pandas में rows और columns filter (select, boolean, sort) pandas groupby आणि aggregation नवशिक्यांसाठी pandas groupby और aggregation शुरुआती pandas मध्ये missing values (NaN, dropna, fillna) pandas में missing values (NaN, dropna, fillna) Python मध्ये EDA (Exploratory Data Analysis) — pandas checklist Python में EDA (Exploratory Data Analysis) — pandas checklist matplotlib आणि seaborn: पहिले charts (storytelling) matplotlib और seaborn: पहले charts (storytelling) Excel VLOOKUP Exact Match (FALSE) for Beginners Excel XLOOKUP Basics for Beginners How to Create a PivotTable in Excel from Scratch Excel IF Function for Decisions (Pass/Fail, High/Low) Excel SUMIF and SUMIFS for Conditional Totals Excel COUNTIF and COUNTIFS Explained Excel INDEX and MATCH Lookup for Beginners How to Remove Duplicates in Excel (Data Tab) Excel CONCAT, TEXTJOIN and & to Join Text Excel FILTER Function (Dynamic Array) for Beginners Excel VLOOKUP Exact Match (FALSE) — मराठी Excel VLOOKUP Exact Match (FALSE) — हिंदी Excel XLOOKUP Basics — मराठी नवशिक्यांसाठी Excel XLOOKUP Basics — हिंदी शुरुआती Excel PivotTable सुरवातीपासून — मराठी Excel PivotTable शुरू से — हिंदी Excel IF Function (High/Low, Pass/Fail) — मराठी Excel IF Function (High/Low, Pass/Fail) — हिंदी Excel SUMIF आणि SUMIFS — मराठी Excel SUMIF और SUMIFS — हिंदी Excel COUNTIF आणि COUNTIFS — मराठी Excel COUNTIF और COUNTIFS — हिंदी Excel INDEX आणि MATCH Lookup — मराठी Excel INDEX और MATCH Lookup — हिंदी Excel Remove Duplicates (Data Tab) — मराठी Excel Remove Duplicates (Data Tab) — हिंदी Excel CONCAT, TEXTJOIN आणि & — मराठी Excel CONCAT, TEXTJOIN और & — हिंदी Excel FILTER Function (Dynamic Array) — मराठी Excel FILTER Function (Dynamic Array) — हिंदी