From chat to the terminal|INEMA.CLUB-PRO

Lesson 6 · 20 min

Git: the safety net for undoing any change

For a task, an agent can change ten files at once. Without history, you don’t know what changed or how to go back. With Git, each good version is saved with a date and explanation, and you can undo a change you didn’t approve with one command.

Start the lesson
Sheets of paper pinned in a row on a clothesline against a dark wall, beside a laptop.

In this lesson, you will

  1. 1Start the history only in the project folder
  2. 2Read git status and git diff before saving
  3. 3Save a version with a message that says what changed
  4. 4Restore a file with git restore and undo a version with git revert

Objective: save versions with status, add, diff, and commit, and undo an agent’s change with git restore, without panicking.

01Changed, staged, saved

The three stages of a file in Git. Click each one.

Scroll down: each step below lights up its part of the diagram.

  1. 1/5

    In the folder

    The agent created or changed files. git status shows each one: "Untracked files" are files Git isn’t tracking yet; "Changes not staged" are changes that haven’t been staged.

  2. 2/5

    Staged

    git add with the file name stages only that file for the next version (Git calls this staging). git diff --cached shows, line by line, what will go in.

  3. 3/5

    Version saved

    The commit clips together what was staged. The message is the photo caption: a verb and an object, such as "Add contact section." "update" won’t tell you anything a month from now.

  4. 4/5

    Back

    Change not saved yet: git restore returns the file to the last saved version (and discards your changes). Version already saved: git revert creates a new version that undoes the previous one without erasing the history.

  5. 5/5

    The cycle with the agent

    Commit before you ask. The agent makes changes. Check them with status and diff. Like them: add and commit. Don’t like them: restore. Each good version becomes a point you can return to.

Git runs only on your computer, without internet. GitHub is another optional step (lesson 8).

02From git init to the first undo

Click each step.

1. Start the history

Inside meu-primeiro-agente, git init creates the history. Never run it in your entire personal folder.

git config user.name and user.email, without --global, say who saves changes, only in this project. The email appears in each version and is visible if the folder is published.

It respondsInitialized empty Git repository in …\meu-primeiro-agente\.git\

03Git commands

In the meu-primeiro-agente folder. Replace anything inside < >.

cmd · start and identify yourself (only in this folder)
cd %USERPROFILE%\projetos\meu-primeiro-agente
git init
git config user.name "<Seu Nome>"
git config user.email "<seu@email.com>"
git status
cmd · look, stage, and save the first version
git add README.md AGENTS.md .gitignore .env.example index.html
git diff --cached
git commit -m "primeira versão"
git log --oneline
cmd · after the agent changes something
git status
git diff
cmd · don’t like it: restore the file
git restore index.html
git status
cmd · like it: save the new version
git add index.html
git commit -m "<what changed, with a verb>"
cmd · undo a saved version
git log --oneline
git revert <código da versão>
Simulation: illustrative example
On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .env.example
        .gitignore
        AGENTS.md
        README.md
        index.html

"Untracked files" = outside the history. .env is not on the list: .gitignore worked.

04Rehearse: save, break, and go back

The agent will change index.html along the way.

Missions

  1. 1Start the history in this folder.
  2. 2Check the status of the files.
  3. 3Stage everything that isn’t ignored.
  4. 4Save the first version with the message primeira versão.
  5. 5The agent rewrote the page, and you didn’t like it. Check the status.
  6. 6Restore index.html to the last saved version.
  7. 7Check that everything is back as it was.
Command Prompt · simulation

Simulation: codes and counts in the responses are examples.

05Practice

In the meu-primeiro-agente folder, with the agent open in another cmd window.

E11 · The safety net

20 min

git init, config, status, add, and commit. Ask the agent to make a big change to the page and, if you don’t like it, undo it with git restore.

Done when: you undid an agent change with one command, and git status says "working tree clean".

E12 · Three versions with captions

15 min

Ask for two small changes and save each with a message that says what changed. Then undo the last one with git revert.

Done when: git log --oneline shows the versions with clear messages, including the revert, and the page is back to how it was.

06Test what you learned

The explanation appears after your answer.

Question 1 of 4

The agent made a big change you didn’t approve, and you haven’t saved anything since. What should you do?competency

To learn more

Previous lessonNext lesson