Terminal and Git for AI Work: Review and Undo What an AI Assistant Changes
Hands-on lab · IDE in your browser

Terminal and Git for AI Work: Review and Undo What an AI Assistant Changes

gitignore, read the assistant's edit as a diff, keep the change you asked for while restoring the tests and behaviour it quietly broke, and undo a bad auto-committed change with git revert.

Time
45 min
Checked steps
5
Level
Beginner
Setup
None
Read step 1

Hands-on labs require Pro · $29.99/mo · cancel anytime

The job

Brightline Books has a small stock tool, shelfbot, and wants to let an AI coding assistant work on it. You set things up so that is safe. You learn to move around a project from the terminal, put it under git before anything edits it, and then supervise the assistant: it adds the discount function you asked for, quietly changes how prices round and deletes the tests that would notice. Later it commits a faster loader that breaks on titles with commas. You find both in the diff and undo exactly the parts that should not be there.

5 steps, each checked when you finish it

A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.

  1. 1

    Find your way around in the terminal

    AI coding tools, notebooks and servers all end up in a terminal: a text window where you type a command, press Enter and read what it prints.

  2. 2

    Start tracking with git before anything edits your code

    In a minute an AI assistant will edit this project.

  3. 3

    Let the assistant edit, then read what it did

    You ask an AI coding assistant for one thing: *add a function that applies a percentage discount*.

  4. 4

    Keep the good part, undo the rest

    The discount function is what you asked for.

  5. 5

    Undo a bad commit without rewriting history

    Agents running in auto mode often commit their own work.

Step 1 as it appears in the lab

The lab’s own text. The hint and the solution stay inside the lab.

Step 1: Find your way around in the terminal

AI coding tools, notebooks and servers all end up in a terminal: a text window where you type a command, press Enter and read what it prints. Open the terminal tab (it starts in your home folder, ~). CHEATSHEET.md lists every command this lab uses.

The folder shelfbot/ holds Brightline's small stock tools: a price module, a stock loader, a report script, tests and a CSV of books.

Do this

1. Look around. Try each of these and read the output:

pwd                      # where you are
ls                       # what is here
cd shelfbot              # go into the folder
ls -la                   # everything, including hidden files
head -n 4 data/stock.csv # the first lines of the stock list
wc -l data/stock.csv     # how many lines it has
grep -rn "def line_total" .   # which file defines line_total?

2. Run the report and keep its output. Still inside shelfbot/:

mkdir out
python3 report.py > out/report.txt

> sends what a command prints into a file instead of the screen. Open out/report.txt with cat to see it.

3. Answer the questions below using the commands, then click Check.

CHEATSHEET.md, the file you edit27 lines
# Terminal and git cheatsheet

## Moving around
    pwd                      where am I?
    ls                       what is here?   (ls -la shows hidden files too)
    cd shelfbot              go into a folder     cd ..   go up one     cd ~   go home
    cat file.txt             print a file         head -n 5 file.txt   the first 5 lines
    wc -l file.txt           count lines
    grep -rn "word" .        search every file below here for "word", with line numbers
    mkdir out                make a folder        mv a.txt out/        move a file
    python3 report.py > report.txt     run a script and save what it prints

## git
    git init                            start tracking this folder
    git status                          what changed since the last commit?
    git add <file> / git add .          stage changes for the next commit
    git commit -m "message"             save a snapshot
    git log --oneline                   the history, newest first
    git diff                            what changed, line by line (unstaged)
    git diff --stat                     which files changed, and how much
    git restore <file>                  throw away uncommitted changes to a file
    git restore --source=HEAD <file>    bring back a file deleted since the last commit
    git revert HEAD                     a NEW commit that undoes the last one
    git show HEAD                       what the last commit changed

In the diff: lines starting with - were removed, lines starting with + were added.
Press q to leave a long git log or diff.
Provided for you:ai_edit.pyshelfbot/README.mdshelfbot/data/stock.csvshelfbot/pricing.pyshelfbot/report.pyshelfbot/stock.pyshelfbot/tests/__init__.pyshelfbot/tests/test_pricing.pyshelfbot/tests/test_stock.py

Frequently asked questions

Do I need to install git or use GitHub?

No. The lab environment has a terminal with git and Python ready. Everything happens in a local repository; no account is needed.

What is the difference between git revert and git reset?

git revert adds a new commit that undoes an earlier one, so history keeps both and anyone who already has the old commit is unaffected. git reset moves the branch back as if the commit never happened, which rewrites history. On shared branches, revert is the safe choice.

Why read the diff when the assistant already explains its changes?

Summaries describe intent, not every edit. In this lab the assistant's summary says it tidied a couple of things; the diff shows it changed price rounding and deleted the tests that would have caught the change.

Is this lab only for programmers?

It is for anyone who will let an AI tool touch files, including analysts and writers. The commands are the same for code, notebooks, prompts and documents.

Why git is the safety net for AI-assisted coding

AI coding assistants edit many files at once and describe their work in a friendly summary that is not a review. The review is the diff: a line-by-line comparison with the last commit, which only exists if the project is under version control before the assistant starts. The terminal and a handful of git commands are what make AI edits safe to accept. This lab teaches them on a real, if small, Python project. You navigate with pwd, ls, cd, grep and wc, redirect a script's output to a file, initialise a repository with a .gitignore, and commit. Then a simulated assistant makes the kinds of changes real ones make: scope creep, a subtle rounding change, deleted tests, and an auto-committed refactor that breaks CSV parsing. You review with git status and git diff, restore single files, commit only what you checked, and undo the bad commit with git revert.