Go from never having used a coding agent to working productively and safely with one. The learner should understand what an agent is and how it differs from a chat assistant. They should choose a tool, set up a protected first project, describe tasks the agent can do well, and follow and verify its work. They should recover from bad changes, manage context, and plan bigger changes. They should also use tests as the definition of done and run everyday workflows (bug fixes, features, writing tests, codebase exploration, scripts, small tools, refactors). Throughout, they should keep secrets and systems safe and keep their own understanding growing instead of outsourcing it.
Undoing with git: discard, reset, revert
card 4 of 6
Discard one file, then everything
builds on: git status and reading a diff
First check what you are about to lose. Then discard one file, then all the remaining edits. If you already ran `git add` on a file, use `git restore --staged --worktree <file>` for it. Brand-new untracked files are left alone by both commands. Delete them yourself if you don't want them.
$ git status
modified: src/app.py
modified: src/utils.py
$ git diff src/utils.py
diff --git a/src/utils.py b/src/utils.py
--- a/src/utils.py
+++ b/src/utils.py
@@ -1,3 +1,3 @@
import time
-TIMEOUT = 30
+TIMEOUT = 0
$ git restore src/utils.py
$ git status
modified: src/app.py
$ git reset --hard
HEAD is now at 3f9c2e1 Add login form
$ git status
nothing to commit, working tree clean
Terms on this card
- untracked
- A new file git has never been told about. `git status` lists it separately, and restore or reset don't touch it.
- git add
- Marks changes to go into the next commit. Changes marked this way are called staged.
- --staged --worktree
- Options for `git restore` that undo a file's staged changes and its working-tree changes in one go.
- git restore
- Puts a file back to how it was in the last commit, discarding its uncommitted edits permanently. If you already ran `git add` on the file, add `--staged --worktree` to go all the way back to the last commit.
- git
- A tool that records versions of a project's files over time. Its data lives in the hidden `.git` folder.
Lesson goal: Choose the right undo. Discard uncommitted changes to files, return to the last commit, or revert a commit that is already made. Know which of these permanently loses work. ·
the whole lesson