Extract and apply deltas between two directories of the same project. Use when merging results from a parallel worktree or separate checkout where git push/pull isn't practical.
Extract changes from a "future" directory and apply them to the "present"
working tree. Complement to ctx-worktree: worktree splits work apart,
absorb merges results back.
git pull / git mergeValidate directories exist:
ls "<present>" "<future>"
Same-project fingerprint — at least one must match:
go.mod module path, or same package.json name.context/CONSTITUTION.md exists in bothDetect git status in each directory:
git -C "<present>" rev-parse --git-dir 2>/dev/null && echo "GIT" || echo "NOGIT"
git -C "<future>" rev-parse --git-dir 2>/dev/null && echo "GIT" || echo "NOGIT"
| Present | Future | Strategy |
|---|---|---|
| git | git | 1 — git fetch + merge-base diff |
| git | no-git | 2 — git diff --no-index |
| no-git | git | 2 — git diff --no-index |
| no-git | no-git | 3 — diff -rNu fallback |
# One-shot fetch — no permanent remote
git -C "<present>" fetch "<future>" HEAD --no-tags
# Find common ancestor
MERGE_BASE=$(git -C "<present>" merge-base HEAD FETCH_HEAD)
# Generate diff from merge-base to future HEAD
git -C "<present>" diff "$MERGE_BASE" FETCH_HEAD
If merge-base fails (no common history), fall back to Strategy 2.
git diff --no-indexgit diff --no-index "<present>" "<future>" -- . \
':!.git' ':!.git/**'
This works whether either, both, or neither directory has .git/.
diffdiff -rNu "<present>" "<future>" \
--exclude='.git' --exclude='node_modules' --exclude='.venv'
After generating the diff, present a summary before applying:
Delta: <future> → <present>
Strategy: <1|2|3>
Files changed: 12 (+340 / -85)
modified: internal/cli/pad.go, docs/getting-started.md, ...
added: internal/crypto/aes.go
deleted: hack/old-script.sh
Always show this summary and ask for confirmation before applying.
Cross-reference delta files with uncommitted changes in present:
git -C "<present>" status --porcelain
If any files appear in both the delta and the working tree changes, warn explicitly:
WARNING: These files have local changes AND incoming changes:
- internal/cli/pad.go (modified locally + modified in delta)
Applying may cause conflicts or overwrite local work.
Ask the user how to proceed: apply anyway, skip conflicting files, or abort.
Dry-run first (Strategy 1/2):
git apply --check --stat <patch-file>
For Strategy 3:
patch --dry-run -p0 < <patch-file>
Apply (after user confirms):
git apply <patch-file> # Strategy 1/2
patch -p0 < <patch-file> # Strategy 3
If apply fails with conflicts, report which hunks failed and
offer to apply with --reject so the user can resolve manually.
User can pick specific files. Regenerate the diff scoped to those files:
git -C "<present>" diff "$MERGE_BASE" FETCH_HEAD -- file1 file2git diff --no-index "<present>/file1" "<future>/file1"diff -u "<present>/file1" "<future>/file1"Remind the user:
git diffctx-worktree teardown to clean upgit remote add.git/, node_modules/, .venv/git checkout .