Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Undo an Agent's Change

Every job in the warm-up folder ends in its own commit, so the last commit is a checkpoint you can go back to. In this video, you saw an example of a job going wrong and how to undo it, in part or in whole, and what no undo can bring back.

Key Points

  • Undoing a job means going back to your last checkpoint. Start each job from a clean working tree, as in the last lesson, so everything that changed afterward is the job’s doing.
  • git restore puts back a file Git already tracks, as it was in the last commit, as long as you haven’t run git add on it since. If you have, it puts back the version you added. It prints nothing.
  • Restore doesn’t touch new files. A file the job created was never in a commit, so git status still lists it under Untracked files.
  • Git can’t bring back the edits you throw away. They were never committed, so Git has no copy of what git restore discards. Your editor or your agent might keep one, but don’t count on it.
  • git clean -n lists the new files, and git clean -f removes them. Read the list first: -f removes every file on it, including one of yours that you haven’t committed yet. It skips new folders.
  • Undo some files to keep part of a job, or every file to drop all of it. Review and commit the part you keep, so it becomes the next checkpoint. After undoing a whole job, git status says working tree clean.
  • An agent’s own undo is narrower than it looks. It usually puts back only the files the agent edited itself, not files that only its commands changed, such as code a formatter rewrote.
  • Nothing in Git or the agent brings back what happened outside the folder’s files, such as a file deleted in another folder, a reset database or a sent message. Your permissions decide which commands run without asking.

The Undo, Step by Step

The job in the video is an example, not a recorded session. Asked to make check-words.js also print the words that pass, the agent did that, then removed the three words that break a rule from words.txt and moved them into a new file, failed-words.txt. Even with your instruction file, an agent can slip like this. Here’s what git status showed afterward:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Every job in the warm-up folder now ends in its own commit. In this video, you’ll see what to do when a job goes wrong. Here’s an example of a bad job. Your agent’s mistakes will be different, but the undo works the same way.

00:15 Before the job, git status said the working tree was clean, so your last commit is the checkpoint.

00:22 You ask the agent to make the word checker also print the words that pass. It does that. But it also removes the three words that break a rule from the word list, and moves them into a new file.

00:34 Even with your instruction file, an agent can slip like this. Now git status lists three things. The checker and the word list are modified, and the new file is untracked.

00:45 You want to keep the checker’s change and undo the other two.

00:51 Git restore takes a file Git already tracks, here the word list, and puts it back as it was in the last commit. Git prints nothing. This works as long as you haven’t run git add on the file.

01:03 If you have, restore puts back the version you added. Your turn: pause the video and predict. When you run git status now, is the new file still listed?

01:20 Yes. Restore only puts back files that are in the last commit, and the new file never was. Watch out: Git can’t bring back the edits you throw away with restore.

01:32 They were never committed, so Git has no copy. Your editor or your agent might keep one, but don’t count on it.

01:41 Git clean handles new files. With -n, it only lists what it would remove. Here, that’s the new file. Read that list first. With -f, Git clean removes every file on it, including one of yours that you haven’t committed yet.

01:58 Here the list is right, so you run it. Now git status shows only the checker’s change. If the whole job was wrong, you’d restore the checker too. Then git status says the working tree is clean, back at the last checkpoint.

02:15 Here you want the checker’s change, so review it and commit it as the job’s checkpoint.

02:21 That’s all the Git you need for undoing a job. Git clean, as you ran it here, skips new folders. If git status still lists one, or anything else, the Tooling and Git path covers it.

02:35 Some agents have an undo of their own. Watch out: it usually puts back only the files the agent edited itself, not files that only its commands changed, like code a formatter rewrote.

02:47 The text below this video shows what your agent offers.

02:51 Git and the agent’s undo both stop at the folder’s files. Say a job’s command deleted a file in another folder, reset a database, or sent a message. Nothing in this video brings that back.

03:04 That’s why you chose which commands may run without asking.

03:09 To undo a job, go back to your last checkpoint: git restore for edited files, and git clean for new ones.

03:18 Undo some files to keep part of a job, or every file to drop all of it. Git can’t bring back edits you throw away, and no undo here reaches outside the folder.

03:29 Next is Exercise: Pick the Right Undo. For a few jobs that went wrong, you’ll decide which undo fits each one, or whether anything can.

Become a Member to join the conversation.