Seeing History & Undoing Mistakes
The real payoff of committing arrives now: you can look back through your project's whole history, see exactly what changed, and safely undo mistakes. This is the safety net in action.
Once you're committing snapshots, Git's real value appears: you can travel through your project's history. See every change ever made, compare versions, and - crucially - undo mistakes and recover earlier states. This is the safety net that makes version control worth it, and it's what lets you code fearlessly. Let's look at the everyday commands for history and undoing.
See what happened
Three commands answer 'what's the history?' and 'what changed?'.
git log # the list of commits (your history)
git log --oneline # a compact one-line-per-commit view
git diff # what you've changed but not yet staged
git show <commit> # exactly what a particular commit changedgit log shows the story of your project - every commit, its message, author and time. git diff shows precisely which lines you've changed since the last snapshot, which is invaluable before committing ('let me review what I'm about to save'). Together they mean you're never in the dark about what changed or when - you can always answer 'what did I do here, and why?' by reading the history.Undo, safely
Everyone makes mistakes; Git lets you take them back. There are different 'undos' for different situations.
| Situation | Roughly what you do |
|---|---|
| Edited a file, want it back | Restore it to the last commit |
| Staged something by mistake | Unstage it (it stays edited) |
| Want to see an old version | Check out an earlier commit |
| A commit made things worse | Revert it - a new commit undoing it |
The key comfort: because every commit is saved, you can almost always get back to a known-good state. If something breaks, you're not stuck - you return to the last commit that worked. That's exactly the fearlessness version control promises: mistakes are recoverable, so you can be bold.
The safety net in action
- git log - read your project's history, commit by commit.
- git diff - see exactly what you changed (review before committing).
- Undo mistakes - restore files, unstage, or revert a bad commit.
- You can always get back to a saved good state - so code boldly.
๐ฏ Key takeaways
- Committing pays off here: you can travel your project's whole history and see exactly what changed.
- git log reads your history; git diff shows precisely what you changed (great to review before committing).
- Different situations have different safe undos: restore a file, unstage, view an old version, or revert a commit.
- Because every commit is saved, you can almost always return to a known-good state - so you can code fearlessly.
Frequently asked
I'm scared of undoing things in Git and making it worse. How safe is it really?
Your caution is understandable, but here's the reassuring truth: the everyday undo operations are very safe, precisely because Git's whole design is about not losing your committed work. Once you've committed something, it's saved in your history, and the common ways of 'undoing' - restoring a file to its last committed state, unstaging a change, or reverting a commit - don't erase that history; they move you around within it or add new commits. Reverting a bad commit, for instance, doesn't delete anything: it creates a new commit that undoes the changes, so both the mistake and its undo are in the record and you can always see what happened. The main thing to know is that committed work is hard to truly lose, so as long as you commit regularly, you have a safety net under your undos themselves. There are a few advanced commands that can discard uncommitted changes or rewrite history, and those deserve more care - but you'll learn to recognise them, and they're not part of the basic workflow. A good approach while you're building confidence: commit often (so there's always a recent safe point), use 'git status' and 'git diff' to see exactly what state you're in before doing anything, and prefer 'revert' (which safely adds an undo commit) over more aggressive options when you want to undo a committed change. Start with the gentle undos on small practice projects, and you'll quickly see that Git is more of a safety net than a trap. The fear fades fast once you've recovered from a mistake a couple of times and seen how forgiving it is.
What's the difference between undoing changes and reverting a commit?
They apply to different moments in the workflow, and knowing which is which removes a lot of confusion. 'Undoing changes' usually refers to work you haven't committed yet: you've edited a file but not saved it as a snapshot, and you decide you don't want those edits - so you restore the file back to how it was at the last commit, discarding the uncommitted changes. Similarly, if you staged something by mistake (git add) but haven't committed, you can unstage it, which just takes it out of the next planned commit while keeping your edits. 'Reverting a commit' is for changes you've already committed: the snapshot is part of your history, and you want to undo its effect. Rather than erasing history (which would be messy, especially if others have your commits), 'git revert' creates a brand-new commit that reverses the changes the bad commit made - so your project ends up as if that change never happened, but the full story (the mistake and its reversal) stays visible in the history. The mental model: before you commit, you're 'discarding' or 'restoring' uncommitted work; after you commit, you 'revert' to add a new undo-commit. This distinction also reflects Git's philosophy - uncommitted work is fair game to discard, but committed history is treated as valuable and is undone by adding to it rather than rewriting it. For beginners, the practical takeaway is: to throw away edits you haven't committed, restore the file; to undo something you already committed, use revert. Both are safe parts of the everyday workflow, and both keep you in control.
Related lessons
Your First Repository
Git's core loop is just three ideas: a place to track your work (a repo), a staging area, โฆ
Version Control with GitBranches: Experiment Without Fear
Branches let you work on a new idea in a parallel copy, without disturbing your working veโฆ
Debugging & Problem-SolvingIsolate the Problem
The fastest way to find a bug is to shrink the search area until the bug has nowhere to hiโฆ