Skip to content
English

Switch theme

// How-to · Let agents run safely

Undo agent changes: git checkpoints, worktrees and reflog

git is the most reliable undo button for agents: one branch or worktree per task, frequent commits, and reflog to recover committed states after a mistake.

verified 2026-10-102 official sources

Scenario: Let agents run safely →

Symptoms

  • The agent broke the code and you want to go back a few steps
  • Commits “disappeared” after git reset --hard

Common causes

  • Changes were not committed, or several agents overwrite each other in one working directory

How to fix

  1. Give each agent task its own branch, or its own worktree with git worktree add ../task-x -b task-x
  2. Have the agent commit after each working step so you can roll back gradually
  3. After a mistaken reset --hard, run git reflog to find the earlier commit and git reset --hard <commit> or create a branch from it
  4. git cannot recover changes that were never committed or staged, so commit before starting

Official references

Compiled from official documentation and public discussions on 2026-10-10; not yet reproduced in our own environment. Follow the official docs if they differ.

Data updated: Problems & errors