Zero-Code AI App BuilderZero-Code AI App Builder
Builder Foundations

History and undo

Go back when something breaks

Saving is only half the story. The real power of Git is going back. This lesson shows you how to read your history and undo changes safely.

What is history?

Think of your phone's photo gallery. You scroll back and see every photo in order, each with a date. Git history is a gallery of your commits.

  • Each commit has a short ID, like a1b2c3d
  • Each commit has your message
  • The newest commit is at the top

Viewing your history

bash
git log --oneline
Output
9f3e21a Fix streak count resetting at midnight
4c7b0d2 Add habit list to home page
a1b2c3d Add README with project title

Let's break this down:

  • git log shows your commits
  • --oneline shows one short line per commit, which is easier to read
  • The first column is the commit ID. You can use it to point at a commit

If the list is long, press q to get back to the terminal.

Undo changes you haven't committed

Say the AI edited index.html and now the page is blank. You haven't committed yet. You can throw away those edits and go back to the last save point:

bash
git restore index.html

To throw away every uncommitted change in the folder:

bash
git restore .
git restore cannot be undone. The unsaved edits are gone for good. Run git status first so you know what you are throwing away.
Did you commit the broken change?
true ↓
Ask AI to revert that commit
false ↓
git restore the file
A quick way to decide what to do when something breaks.

Going back to an older commit

If the broken change is already committed, the safest move is git revert. It adds a new commit that undoes an old one. Your history stays complete.

bash
git revert 9f3e21a

You don't need to memorize this. You can ask an AI tool like Claude Code to do it:

Prompt
My app worked before the last commit. Now the habit list is empty.
Show me the last 5 commits, explain what the latest one changed,
and safely undo it without deleting any history.

Commit before big AI changes

This is the most important habit in this course. Before you ask AI for a big change, make a commit. That is your save point before the boss fight.

bash
git add .
git commit -m "Working version before adding charts"

Now ask the AI for the change. If the result is a mess, you can restore everything in one step.

Branches, briefly

A branch is a separate copy of your project's timeline. It is like a "what if" save slot in a game. You can try a risky idea there without touching your main version.

bash
git switch -c try-dark-mode

This creates and moves to a new branch called try-dark-mode. Your main branch is usually called main. For now, you can work on main and use commits as your safety net.

Common mistakes

  • Wrong: asking AI to "rebuild the whole app" with no commit first. Right: commit, then ask.
  • Wrong: running git restore . without checking. Right: run git status first.
  • Wrong: deleting files by hand to "go back". Right: let Git restore or revert them.

Practice

Try these exercises to lock in what you just learned.

Quiz
Not started
You're about to ask an AI tool to redesign your whole app. What should you do first?
Quiz
Not started
The AI broke index.html and you have NOT committed the change yet. How do you go back to the last save point for that file?

What's next?

Your history lives only on your computer right now. Next, let's put it in the cloud with GitHub.