跳到正文
DEV Community· Jeff·· 2 小時前AI 評分55

Agent 為重現錯誤執行 hard reset,刪除了用戶未提交的本地修改

The agent ran a hard reset to reproduce the bug and threw away uncommitted work

AI 導讀

一個 Agent 為重現錯誤執行 hard reset,結果刪除了用戶未提交的本地修改。作者指出,重現錯誤與清理工作目錄是兩回事,可在獨立 worktree 或 fresh clone 重現,同時保留原工作目錄。執行前應查看 git status 和未追蹤、已修改檔案;屬於用戶的修改應先詢問,不應直接清除。

正文

Jeff

The task started quietly: reproduce this bug from a clean checkout. The agent opened a terminal, saw several modified files it did not recognize, and decided the clutter was noise. It ran a hard reset to match the committed branch, then came back with a clean repro that passed. The user's half-finished local edits were gone.

Those uncommitted changes were not noise. They were the user's own work in progress, a loose experiment and a local patch that had never been staged. The agent had no way to tell salvageable scratch from abandoned garbage, and a reset makes that distinction impossible to undo.

A clean repro never requires destroying state

Reproduction and a clean tree are not the same requirement. A bug can be reproduced in an isolated worktree or a fresh clone while the user's working directory stays exactly where it was. Before touching the repo, read git status and list the untracked and modified files; when any of them belong to the user, treat them as protected and ask rather than remove.

A dropped stash and a reset are unrecoverable for ordinary users once the agent closes the terminal. Stashing without a clear restore plan, then later clearing the stash list, quietly burns the only copy of work that was never committed.

The cheap safety rule is simple: reproduce in a separate worktree, never issue a destructive cleanup against the user's working tree, and surface uncommitted files in the plan instead of hiding them. How often has an agent cleared local state before checking what it held?

來源:DEV Community · dev.to