git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/4] git add --resolved

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2026, 17:25 UTC
Message-ID
<20260729172524.4022621-1-gitster@pobox.com>
In-Reply-To
<20260728215219.753678-1-gitster@pobox.com>

When you are the maintainer of a project and make many merges day in, day out, a lot of your time is spent resolving conflicts and adding the results to the index. It is not unusual to have local changes in your working tree that are unrelated to any particular merge [*]. In such cases, 'git add -u', which adds all changes in the working tree to the index, does not help much.

Here is a new option for 'git add' that lets you add paths with resolved conflicts to the index, while keeping unrelated local changes out.

The first three patches perform preliminary refactorings.
 - [1/4] is a totally unrelated code cleanup that almost disappears
   when viewed with 'git show -w', but it was an eyesore to have so
   many lines with broken indentation while working in the vicinity.
 - [2/4] consolidates a helper function to determine whether a line
   is a conflict marker (replacing two slightly different
   definitions).
 - [3/4] introduces a helper that makes registering path removals
   from the index as easy as adding them, complete with automatic
   '--dry-run' and '--verbose' support.

The fourth patch implements the new feature. Relative to v1, the detection of the use of the '-A' option was fixed and the Meson build file was updated to include the new test script, both thanks to Michael Montalbo. In addition, the has_conflict_markers() helper has been tightened to bail early on a binary file.

 1/4: read-cache: reindent
 2/4: merge-ll: consolidate conflict marker scanning logic
 3/4: read-cache: add remove_file_from_index_with_flags()
 4/4: add: introduce '--resolved' option
[Footnote]
 * This is not limited to my own workflow. An earlier message on
   this topic worth mentioning is:
   https://lore.kernel.org/git/CA+55aFxP8j7YbYaRXt-8Y0n8cHafB=FPKMy8gKFYH5QsKX4S=Q@mail.gmail.com/
 Documentation/git-add.adoc |  10 +++-
 builtin/add.c              |  92 ++++++++++++++++++++++++++++---
 diff.c                     |  25 +--------
 merge-ll.c                 |  56 +++++++++++++++++++
 merge-ll.h                 |   2 +
 read-cache-ll.h            |   3 ++
 read-cache.c               |  89 +++++++++++++++++-------------
 rerere.c                   |  38 +++----------
 t/meson.build              |   1 +
 t/t2207-add-resolved.sh    | 108 +++++++++++++++++++++++++++++++++++++
 10 files changed, 323 insertions(+), 101 deletions(-)
 create mode 100755 t/t2207-add-resolved.sh
Range-diff against v1:
4:  c503fbb785 = 1:  e46fe3e887 read-cache: reindent
1:  03ea86d803 = 2:  b5490819bd merge-ll: consolidate conflict marker scanning logic
2:  e94e3c1390 = 3:  e1f4aba480 read-cache: add remove_file_from_index_with_flags()
3:  73679d6b69 ! 4:  b1308a0ca1 add: introduce '--resolved' option
    @@ builtin/add.c: int cmd_add(int argc,
     -	if (addremove && take_worktree_changes)
     -		die(_("options '%s' and '%s' cannot be used together"), "-A", "-u");
     +	die_for_incompatible_opt3(take_worktree_changes, "-u/--update",
    -+				  0 <= addremove_explicit, "-A/--all",
    ++				  0 < addremove_explicit, "-A/--all",
     +				  add_resolved, "--resolved");
      
      	if (!show_only && ignore_missing)
    @@ merge-ll.c: int is_conflict_marker_line(const char *line, unsigned long len, int
     +			has_markers = 1;
     +			break;
     +		}
    ++		if (buffer_is_binary(sb.buf,
    ++				     ULONG_MAX <= sb.len ? ULONG_MAX : sb.len))
    ++			break;
     +	}
     +	fclose(f);
     +	strbuf_release(&sb);
    @@ merge-ll.h: enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
      
      #endif
     
    + ## t/meson.build ##
    +@@ t/meson.build: integration_tests = [
    +   't2204-add-ignored.sh',
    +   't2205-add-worktree-config.sh',
    +   't2206-add-submodule-ignored.sh',
    ++  't2207-add-resolved.sh',
    +   't2300-cd-to-toplevel.sh',
    +   't2400-worktree-add.sh',
    +   't2401-worktree-prune.sh',
    +
      ## t/t2207-add-resolved.sh (new) ##
     @@
     +#!/bin/sh
-- 
2.55.0-609-g9a17695db7
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 30 in “git add --resolved”
  1. 0/4 git add --resolvedJunio C Hamano, Jul 28, 2026
  2. 1/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 28, 2026
  3. 2/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 28, 2026
  4. 3/4 add: introduce '--resolved' optionJunio C Hamano, Jul 28, 2026
  5. Michael MontalboJul 29, 2026
  6. Junio C HamanoJul 29, 2026
  7. Junio C HamanoJul 29, 2026
  8. Junio C HamanoAug 2, 2026
  9. Junio C HamanoJul 29, 2026
  10. Michael MontalboAug 2, 2026
  11. Junio C HamanoAug 2, 2026
  12. Michael MontalboAug 3, 2026
  13. 4/4 read-cache: reindentJunio C Hamano, Jul 28, 2026
  14. 0/4 git add --resolvedJunio C Hamano, Jul 29, 2026
  15. 1/4 read-cache: reindentJunio C Hamano, Jul 29, 2026
  16. 2/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 29, 2026
  17. 3/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 29, 2026
  18. 4/4 add: introduce '--resolved' optionJunio C Hamano, Jul 29, 2026
  19. Junio C HamanoJul 29, 2026
  20. Michael MontalboJul 29, 2026
  21. Junio C HamanoJul 30, 2026
  22. Michael MontalboAug 2, 2026
  23. 0/4 git add --resolvedJunio C Hamano, Jul 31, 2026
  24. 1/4 read-cache: reindentJunio C Hamano, Jul 31, 2026
  25. 2/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 31, 2026
  26. 3/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 31, 2026
  27. 4/4 add: introduce '--resolved' optionJunio C Hamano, Jul 31, 2026
  28. Jeff KingAug 1, 2026
  29. Junio C HamanoAug 1, 2026
  30. Junio C HamanoAug 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.