hotai.news
← Back to AI WikiAI Wiki / Solve a problem

AI changed unrelated files: how do you narrow the patch without losing existing user edits?

When AI edits unrelated files, compare the before-and-after working tree and individual changes to distinguish its edits from existing user work. Do not reset the repository or discard all uncommitted files.

HotAI.news · Sources checked with CodexPublished on 2026-10-20Sources checked on 2026-10-20
Our take

Start troubleshooting here

When AI edits unrelated files, compare the before-and-after working tree and individual changes to distinguish its edits from existing user work. Do not reset the repository or discard all uncommitted files. Retain necessary changes hunk by hunk and reverify affected paths so the final commit has a clear scope without losing uncommitted work.

01

Preserve the working-tree state from before the task

Typical examples are a button fix that reformats the site or generated code that unexpectedly upgrades a lockfile. Preserve current diffs and untracked-file listings and identify any baseline from before the task. Staged and unstaged edits may belong to different work; without a baseline, attribution requires more careful inspection.

02

Separate new changes from existing edits hunk by hunk

Inspect working-tree differences, staged differences and new files separately against the request. Formatting can alter many lines in one file, so inspect meaning. If user and AI edits overlap, do not delete an entire file’s changes based on assumed ownership. Identify separable portions and preserve evidence of overlaps.

03

Select task-related changes while preserving overlapping edits

Organize the task patch with selective staging and narrowly correct changes confirmed to be unrelated and newly introduced. Manually merge overlaps and inspect the result instead of using destructive resets. Compare or extract irrelevant formatting changes in a copy, retaining a recovery copy where needed so mistakes do not make the original content unrecoverable.

04

Check staged content and intended behavior together

Before committing, inspect staged differences for only necessary files and hunks and run risk-appropriate checks. Confirm existing user edits remain and untracked files were not deleted. Report patch scope and verification. A successful commit or a smaller diff alone does not establish preservation of previous work.

This article reset no repository and cleaned no private files. If attribution is uncertain without a baseline, preserve those edits and record the uncertainty rather than deleting them. Selective staging controls commit contents but does not resolve behavioral conflicts; combined edits in one file still need testing.

Checked sources

These sources support the concepts and methods described here. Examples and test scope are labeled separately; check the version of the tools you use.

Back to AI Wiki ↗