Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Git: How to Fix (Almost) Every Mistake

11. 05. 2017 1 min read intermediate

Made a mistake in Git? Relax — Git almost never deletes anything permanently.

Commit to Wrong Branch

git branch correct-branch git reset –hard HEAD~1 git checkout correct-branch

Change Commit Message

git commit –amend -m “new message”

Forgotten File

git add forgotten.py git commit –amend –no-edit

Undo a Commit

git reset –soft HEAD~1

Deleted Branch

git reflog git checkout -b recovered abc1234

Merge Conflict

git status

Git: How to Fix (Almost) Every Mistake

git add resolved.py git commit

Revert a Pushed Commit

git revert abc1234

Lost Changes After Hard Reset

git reflog git branch recovery HEAD@{2}

Ignore a Tracked File

git rm –cached config.local.yml echo “config.local.yml” >> .gitignore

Golden Rule

Git reflog is your safety net. As long as gc hasn’t run, your data is there.

gittroubleshooting
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.