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.
Discussion
0Only signed-in visitors can comment. Sign in to write.
Nobody has spoken up yet. Be the first.