diff --git a/global/多 Agent 开发使用项目内 worktree,合并后删除.md b/global/多 Agent 开发使用项目内 worktree,合并后删除.md new file mode 100644 index 0000000..fb5961f --- /dev/null +++ b/global/多 Agent 开发使用项目内 worktree,合并后删除.md @@ -0,0 +1,29 @@ +--- +title: 多 Agent 开发使用项目内 worktree,合并后删除 +type: preference +permalink: main/global/多-agent-开发使用项目内-worktree-合并后删除 +stable_id: 09c668ce-3dec-4054-bd12-30ad6c1ca205 +scope: global +memory_type: preference +project_id: null +usage_profile_id: 0c9feb46-d06e-43cd-9ef0-c5813c84a998 +status: active +revision: 1 +request_id: habit-multi-agent-worktree-20261028-0320 +created_at: '2026-10-27T19:20:50.683448+00:00' +updated_at: '2026-10-27T19:20:50.683448+00:00' +tags: +- multi-agent +- worktree +- git +--- + +一旦采用多 Agent 开发,每个 Agent 使用独立的 git worktree,不在同一工作区并行改同一批文件。 + +worktree 只放在当前 Git 仓库内部、已被 .gitignore 覆盖的目录,优先使用项目根目录下的 Temp/worktrees/<任务名>。禁止放到仓库同级目录、用户主目录、桌面、下载目录、系统临时目录或其他盘符的无关路径,避免污染项目之外的位置。 + +每个 worktree 对应一条独立分支。该 Agent 完成并验证后,先把分支 rebase 到最新主分支,再以 fast-forward 合并进主分支,保持线性历史。合并前确认不含秘密值和临时文件。仓库有远端时,合并后按既有规则 fetch,必要时先 rebase 再推送,不使用 force。 + +合并进主分支后立刻清理:git worktree remove 对应 worktree,随后 git worktree prune;删除 Temp/worktrees 下该任务的目录、合并后已无用的本地分支,以及该 worktree 产生的冗余文件和空目录。主工作区保持干净,不把 worktree 目录提交进 Git,也不留下 worktree 元数据。 + +后续任何「多 Agent 开发」都按这条执行。 \ No newline at end of file