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.
3Save a version with a message that says what changed
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.
01 · Changed, staged, saved
The three stages of a file in Git. Click each one.
Lesson 601 · Changed, staged, savedThe three stages of a file in Git. Click each one.
Golden rule: commit before asking for a big change
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.
Scroll down: each step below lights up its part of the diagram.
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/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/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/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
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).
02 · From 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\
2. Look first
git status tells you what stage each file is at. Always run it before staging anything.
This is where the .gitignore from lesson 5 proves itself: .env doesn’t appear in the list.
Look forAGENTS.md, README.md, .gitignore, .env.example… and no .env.
3. Save
To learn, name the files in git add. The shortcut git add . stages everything that isn’t ignored, including a personal note you forgot in the folder.
git log --oneline shows a short list of versions, one per line.
Good messageCreates README, AGENTS.md, and a list of what not to save
4. Undo
Only in the file, not saved: git restore arquivo. In a saved version: git revert with the version code, which appears in the log.
Check the open file, not just the terminal response.
An erratum, not an erasureRevert makes a correction and leaves all three versions in the history.
03 · Git 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
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.
Untracked files: files Git is not tracking yet.
Changes to be committed: staged; they’ll be included in the next version.
Changes not staged: changed, but not staged.
nothing to commit, working tree clean: nothing has changed since the last version.
git init in your personal folder: Git starts looking at Documents, Downloads, everything. Run cd first and check the path.
Skipping Git: the agent’s first bad change becomes manual rework.
"Please tell me who you are": the name and email git config are missing.
04 · Rehearse: save, break, and go back
The agent will change index.html along the way.
Missions
1Start the history in this folder.
2Check the status of the files.
3Stage everything that isn’t ignored.
4Save the first version with the message primeira versão.
5The agent rewrote the page, and you didn’t like it. Check the status.
6Restore index.html to the last saved version.
7Check that everything is back as it was.
Command Prompt · simulation
Simulation: codes and counts in the responses are examples.
05 · Practice
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.
06 · Test 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
Correct
With a commit from before the change, git restore restores the file in one command. That’s why you should commit before asking for a major change.
Not this one
With a commit from before the change, git restore restores the file in one command. That’s why you should commit before asking for a major change.Review: Rehearse: save, break, and go back
Question 2 of 4
Why name the files in git add instead of always using git add .?
Correct
The dot includes everything that isn’t ignored, including a forgotten personal note. Use the shortcut only after checking the status.
Not this one
The dot includes everything that isn’t ignored, including a forgotten personal note. Use the shortcut only after checking the status.Review: From git init to the first undo
Question 3 of 4
Which of these commit messages will help you a month from now?
Correct
Verb and object: the version list already tells you what changed, without opening a file.
A saved version was wrong. Which command undoes it without erasing the history?
Correct
Revert is like a newspaper correction: it creates a new version that undoes the previous one. Restore is for changes that aren’t saved yet.
Not this one
Revert is like a newspaper correction: it creates a new version that undoes the previous one. Restore is for changes that aren’t saved yet.Review: Changed, staged, saved
Test complete
You got {a} out of {n} right. Get them all right to mark the lesson complete.
Choose an option. The explanation appears after your attempt.