deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Git 2.56's git add --resolved stages only conflicted files, but its marker check has limits

Git 2.56 adds git add --resolved, a flag that stages only paths still marked as unmerged and rejects files with leftover conflict markers. Hands-on testing shows the safety check has two gaps.

Git 2.56's git add --resolved stages only conflicted files, but its marker check has limits

A new flag for an old habit

Git 2.56 ships with a new git add option, --resolved, aimed at a routine mistake in merge-conflict workflows: finishing a resolution with git add . and sweeping up every other dirty file in the working tree at the same time. According to a hands-on write-up on dev.to, the flag stages only the paths Git still considers unmerged, and it is designed to refuse to stage any of those paths that still contain leftover conflict markers.

Because Git 2.56 has not yet reached the Ubuntu repositories — the test environment only had version 2.43.0 — the author built 2.56.0 from the kernel.org source tarball. The built-in help describes the option as adding "conflict-resolved tracked files".

The core behavior holds up

In a test repository, two branches both modified file1.txt and file2.txt to force a conflict, both files were resolved, and an unrelated edit was made to a third file, file4.txt. Plain git add . staged all three. git add --resolved . staged the two resolved files and left file4.txt untouched, as git status --short confirmed: the unrelated path showed a change only in the working-tree column, with nothing staged.

The marker guard also behaves as documented when the index is in a genuine conflict state. With one file cleanly resolved and another deliberately left containing markers, the command aborted with "fatal: the following paths still have conflict markers" and exit code 128. The check is atomic: the correctly resolved file stayed unmerged in the index as well, so a single bad path blocks the entire invocation rather than allowing partial staging. Only after the markers were removed did a second run stage both files.

Two gaps in the safety net

The testing surfaced two limitations.

The first concerns when the marker check applies at all. The flag only examines paths that currently hold conflict-stage entries in the index; it does not scan file contents generally. The author found this by accident: after a git reset between test scenarios, the unmerged entries collapsed into ordinary index entries, and a subsequent git add --resolved call exited cleanly, printed nothing — even with -v — and staged nothing, despite the file still containing genuine marker lines. Any reset or add sequence that clears the unmerged state also silently disables the marker guard for that path.

The second is granularity. When the author resolved a conflict and, in the same edit, added an extra debug line to that same file, --resolved staged it without complaint. The flag separates unrelated paths from conflicted ones; it cannot separate unrelated edits inside the file you were actually meant to fix.

No measurable performance cost

The write-up also timed git add --resolved . against plain git add . on a repository with 3,000 pre-resolved conflicting files, five runs each. The results overlap heavily: the new flag's runs ranged from 0.202s to 0.820s, while plain git add ranged from 0.168s to 1.404s — the slowest single measurement in the entire set came from the plain command. Scanning conflicted files for marker text did not register as a consistent overhead at that scale.

Why it matters

Ending a conflict with git add . is muscle memory for many developers, and it periodically produces merge commits that contain unrelated work-in-progress. A flag that stages only unmerged paths removes that failure mode at no measurable cost, which makes it an easy default for anyone on Git 2.56 or newer. The caveats matter, though: the conflict-marker guard is tied to index state rather than file contents, so it disappears once a path is no longer marked unmerged, and it offers no protection against stray edits within the files being resolved. Treat the flag as a useful guardrail, not a replacement for reviewing the staged diff before you commit.

  • #git
  • #version-control
  • #developer-tools
  • #merge-conflicts
  • #open-source

Related posts