Skip to content

Suggest refactoring undo #31044

@trainliang

Description

@trainliang

Description

My project structure has not been easy to use since using opencode undo:
Project structure External-all main project directory (no git or main git), internal three or two multi-end codes are managed by git respectively. In this case, no undo in the system can be used for any code management

It is recommended to refactor undo. Compared with other codex and claudecode, git snapshot cannot satisfy code tracking when there are multiple sub-repositories and there is no git repository at the root of the project, resulting in the inability to roll back code files in a large number of scenarios, and then information is lost, which is a major flaw.

Plugins

/undo

OpenCode version

1.16.2

Steps to reproduce

No response

Screenshot and/or share link

Let me deeply analyze OpenCode’s file operations and undo mechanism in a multi-sub-repository scenario.

The analysis results are very clear. Here are the full conclusions:


OpenCode Undo tracking problem in multi-sub-repository scenario

Root cause

OpenCode uses a separate hidden Git repository (~/.local/share/opencode/snapshot/{projectId}/) to track file changes instead of using the project's own Git. Before each tool call, create a snapshot with git add . && git write-tree.

**Git itself does not index the contents of sub-Git repositories (including submodules). ** Git treats the submodule directory as a pointer to a specific commit (a blob) and does not track file changes within it.

Specific impact

Capabilities Main repository files Submodule files
Edit Modify files Normal Normal
Snapshot Tracking Normal Unable to Track
/undo Undo Normal Do not roll back changes in submodules
Review Panel Normal Do not show submodule changes
Diff View Normal Do not show submodule changes

Known GitHub Issues Confirmation

"Unfortunately, git will NOT index child git repos (including submodules) and there's no way to make it."

Practical impact in your project

Taking the gaokao-server submodule as an example, 6 files are currently modified (Dockerfile, application-dev.yml, etc.). If I edit files within these submodules during this session:

  1. The Edit tool itself works properly — files can be modified correctly
  2. But /undo cannot roll back these changes — because the snapshot system cannot track changes within submodules
  3. You need to manually restore files within the submodule via git checkout

Comparison at the tool level

Tools Submodule Change Detection Submodule Undo
OpenCode snapshot Untraceable Cannot Undo
code-review-graph detect_changes Need to specify submodule repo_root Not applicable
Native git Need to enter submodule operation git checkout can be restored

Possible mitigation options

  1. After editing the submodule file, immediately do git commit in the submodule - so that even if undo fails, it can be restored through git revert
  2. Create a separate OpenCode project for each submodule — track separately, but lose the unified context across repositories
  3. Use JetBrains IDE’s Local History — it does not rely on git and can track file changes in any directory
  4. Waiting for an official fix from OpenCode — Issue Opencode Desktop - files touched in submodules aren't shown in Review panel #10658 discussed creating independent snapshots for each submodule, but it has not been implemented so far

Suggestions

For your multi-sub-repository project, the safest way is: after editing the files in the sub-module, directly git add && git commit** in the sub-module instead of relying on OpenCode's /undo. This ensures that the code can be restored through git's native capabilities at any time.

Operating System

macos、debian

Terminal

cli

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions