Skip to content

Commit f8c0b99

Browse files
skulidropekclaude
andcommitted
fix(state-repo): merge unrelated histories instead of reset to preserve local history
Using git reset --soft discards local commits. Replace with git merge --allow-unrelated-histories -X ours so both the local and remote root commits are preserved in the graph. Local files win on conflict, which is the correct default for a state repo. INVARIANT: ∀ local ∈ Repos: ¬∃ancestor(local, remote) → merge_unrelated(local, remote, ours) ∧ ∃ancestor(local, remote) → rebase_sync(local, remote) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c36f412 commit f8c0b99

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

packages/lib/src/usecases/state-repo.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,16 @@ const adoptRemoteHistoryIfOrphan = (
253253
return // Histories are related — normal rebase in stateSync will handle it
254254
}
255255

256-
yield* _(Effect.logWarning(`Local history has no common ancestor with ${remoteRef}; realigning with remote`))
257-
yield* _(git(root, ["reset", "--soft", remoteRef], gitBaseEnv))
258-
yield* _(Effect.log(`Realigned with remote history from ${remoteRef}`))
256+
// Merge unrelated histories so both are preserved; prefer local on conflict
257+
yield* _(Effect.logWarning(`Local history has no common ancestor with ${remoteRef}; merging unrelated histories`))
258+
yield* _(
259+
git(
260+
root,
261+
["merge", "--allow-unrelated-histories", "--no-edit", "-s", "recursive", "-X", "ours", remoteRef],
262+
gitBaseEnv
263+
)
264+
)
265+
yield* _(Effect.log(`Merged unrelated histories from ${remoteRef}`))
259266
})
260267

261268
export const stateInit = (

0 commit comments

Comments
 (0)