]> git.ipfire.org Git - thirdparty/git.git/commit
add: introduce '--resolved' option
authorJunio C Hamano <gitster@pobox.com>
Fri, 31 Jul 2026 12:56:05 +0000 (05:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 31 Jul 2026 15:52:16 +0000 (08:52 -0700)
commit94cf62176ec5e416b7748d60b59bf8f6aa6dd7b3
treedf0bb583d539a7489a791c333819b7ab16d21de1
parent341ce9229e9b5619b686ed9d169b54e33b29f594
add: introduce '--resolved' option

During a conflicted merge, rebase, or cherry-pick, 'git add -u' is a
handy way to add modified paths to the index.  However, '-u'
indiscriminately adds all modified tracked paths, including unmerged
paths that may still contain unresolved conflict markers.  It also
adds tracked files modified in the worktree that are not involved in
the ongoing merge.

The latter is not a huge problem for "git rebase", which refuses to
start with any local changes, but is a problem for "git merge",
which is often run with local changes in maintainer workflows.

Introduce 'git add --resolved' to add only unmerged paths, limited
by an optional pathspec, where no conflict markers remain in the
working tree.

Before modifying the index, scan unmerged regular files for leftover
conflict markers using a new helper, has_conflict_markers(), defined
in merge-ll.c in terms of the is_conflict_marker_line() helper we
introduced earlier.  If any unmerged path still contains conflict
markers, show an error listing the conflicted paths and abort
without updating the index.  Otherwise, add these unmerged paths
that do not have conflict markers to the index.

Note that unmerged paths without conflict markers (such as binary
files and deletions) are added as resolved using add_file_to_index()
and remove_file_from_index_with_flags().  Tracked files that were
not in a conflicted state are ignored by '--resolved'.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-add.adoc
builtin/add.c
merge-ll.c
merge-ll.h
t/meson.build
t/t2207-add-resolved.sh [new file with mode: 0755]