Open daily from 9:00 to 20:00Get in touch
NewWe collected answers to the questions people ask most oftenOpen the section →
🍪 Cookies and personal data

We use cookies to keep the site working and make it more convenient, and we process anonymised data about your visit. The details are in our privacy policy.

Rolling back: how to restore a file or a whole commit

31.08.2026 ~1 min read
Rolling back: how to restore a file or a whole commit

Ruined a file — that is what history is for. It matters to tell three cases apart: restoring a file, undoing the last commit, and undoing a commit that has already gone to the server.

git checkout -- file       restore the file as it is in history
git reset --soft HEAD~1    undo the commit, keep the changes
git revert COMMIT          undo a commit with a separate entry

⚠️ The difference between the last two matters. reset rewrites history — fine while the commit has not been pushed. Once it has, use revert: it does not erase the past but adds a reversing entry, and everyone else’s history stays intact.

More lessons in this course

Discussion

0

Only signed-in visitors can comment. Sign in to write.

Nobody has spoken up yet. Be the first.

Still have questions?We reply within one business day — write to us whichever way suits you.
Contact us