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

[PATCH v4 0/3] checkout -m: recreate conflict labels

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Oct 13, 2026, 15:47 UTC
Message-ID
<cover.1791906474.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1790761727.git.phillip.wood@dunelm.org.uk>

When "git checkout -m <path>" recreates a merge conflict, it uses the labels "base", "ours", "theirs", rather than the labels used by the original merge. This short series teaches the ort machinery to write the labels to ".git/MERGE_LABELS" when it switches to a merge result containing conflicts, so that "git checkout -m" can then read that file and use the same labels.

Changes since V3:
 - added patch 2 to cache merge config settings and conflict labels
Changes since V2:
 - only write ".git/MERGE_LABELS" when there are conflicts and added
   a check to an existing "checkout -m <branch>" test
 - change write_merge_labels() to take an array of labels
 - use a local variable to store the internal merge state when writing
   labels
 - use strbuf_detach() rather than xmemdupz() when reading labels
 - add a comment to say we ignore trailing cruft when reading the
   labels file
Changes since V1:
 - use strbuf_getline() rather than strbuf_read_file() to read labels
   so that the newline handling of the reading and writing sides match.

NB ".git/MERGE_LABELS" is still undocumented - I'm hoping to find time to add some documentation for all the MERGE_* files in a future series. Johannes suggested using an index extension to store the labels, but as we already have MERGE_MODE, MERGE_RR and MERGE_MSG I think it is easier just to add another file.

base-commit: 3bc0341126508f78f5869cbfc0005e987efdf0c7
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fconflict-labels%2Fv4
View-Changes-At: https://github.com/phillipwood/git/compare/3bc034112...eda10c234
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/conflict-labels/v4
Junio C Hamano (1):
  checkout -m <path>: cache merge settings
Phillip Wood (2):
  remove_branch_state: convert boolean argument to flags
  merge: remember conflict labels
 branch.c           | 17 ++++++++----
 branch.h           |  4 ++-
 builtin/checkout.c | 66 ++++++++++++++++++++++++++++++++++++++--------
 builtin/commit.c   |  1 +
 merge-ort.c        | 20 ++++++++++++++
 merge.c            | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 merge.h            |  3 +++
 path.c             |  1 +
 path.h             |  1 +
 repository.c       |  1 +
 repository.h       |  1 +
 sequencer.c        |  1 +
 t/t7201-co.sh      | 22 ++++++++++++++++
 13 files changed, 187 insertions(+), 17 deletions(-)
Range-diff against v3:
1:  86ef0f848a = 1:  86ef0f848a remove_branch_state: convert boolean argument to flags
-:  ---------- > 2:  36f3808d2f checkout -m <path>: cache merge settings
2:  182edb2e88 ! 3:  eda10c2340 merge: remember conflict labels
    @@ builtin/checkout.c
      #include "lockfile.h"
      #include "mem-pool.h"
      #include "object-file.h"
    -@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
    - 	struct cache_entry *ce = the_repository->index->cache[pos];
    - 	const char *path = ce->name;
    - 	mmfile_t ancestor, ours, theirs;
    +@@ builtin/checkout.c: static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
    + struct checkout_merged_data {
    + 	int conflict_style;
    + 	int renormalize;
     +	char *base_label, *ours_label, *theirs_label;
    - 	enum ll_merge_result merge_status;
    - 	int status;
    - 	struct object_id oid;
    -@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
    + };
    + 
    ++static void checkout_merged_release(struct checkout_merged_data *data)
    ++{
    ++	free(data->base_label);
    ++	free(data->ours_label);
    ++	free(data->theirs_label);
    ++}
    ++
    + static void checkout_merged_prepare(struct checkout_merged_data *data)
    + {
    + 	int renormalize = 0;
      
      	repo_config_get_bool(the_repository, "merge.renormalize", &renormalize);
    - 	ll_opts.renormalize = renormalize;
    -+	if (read_merge_labels(the_repository, &base_label, &ours_label,
    -+			      &theirs_label)) {
    -+		base_label = xstrdup("base");
    -+		ours_label = xstrdup("ours");
    -+		theirs_label = xstrdup("theirs");
    + 	data->renormalize = renormalize;
    ++	if (read_merge_labels(the_repository, &data->base_label, &data->ours_label,
    ++			      &data->theirs_label)) {
    ++		data->base_label = xstrdup("base");
    ++		data->ours_label = xstrdup("ours");
    ++		data->theirs_label = xstrdup("theirs");
     +	}
    - 	ll_opts.conflict_style = conflict_style;
    + }
    + 
    + static int checkout_merged(int pos, const struct checkout *state,
    +@@ builtin/checkout.c: static int checkout_merged(int pos, const struct checkout *state,
    + 
    + 	ll_opts.renormalize = data->renormalize;
    + 	ll_opts.conflict_style = data->conflict_style;
     -	merge_status = ll_merge(&result_buf, path, &ancestor, "base",
     -				&ours, "ours", &theirs, "theirs",
    -+	merge_status = ll_merge(&result_buf, path, &ancestor, base_label,
    -+				&ours, ours_label, &theirs, theirs_label,
    ++	merge_status = ll_merge(&result_buf, path, &ancestor, data->base_label,
    ++				&ours, data->ours_label, &theirs, data->theirs_label,
      				state->istate, &ll_opts);
    -+	free(base_label);
    -+	free(ours_label);
    -+	free(theirs_label);
      	free(ancestor.ptr);
      	free(ours.ptr);
    - 	free(theirs.ptr);
    +@@ builtin/checkout.c: static int checkout_worktree(const struct checkout_opts *opts,
    + 			pos = skip_same_name(ce, pos) - 1;
    + 		}
    + 	}
    ++
    ++	if (opts->merge)
    ++		checkout_merged_release(&checkout_merged_data);
    ++
    + 	if (pc_workers > 1)
    + 		errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
    + 					      NULL, NULL);
     @@ builtin/checkout.c: static void report_tracking(struct branch_info *new_branch_info)
      
      static void update_refs_for_switch(const struct checkout_opts *opts,
-- 
2.56.0.134.g299a3c16181
Previous: Junio C HamanoNext: Phillip Wood
Message 31 of 35 in “checkout -m: recreate conflict labels”
  1. 0/2 checkout -m: recreate conflict labelsPhillip Wood, Sep 30, 2026
  2. 1/2 remove_branch_state: convert boolean argument to flagsPhillip Wood, Sep 30, 2026
  3. 2/2 merge: remember conflict labelsPhillip Wood, Sep 30, 2026
  4. Junio C HamanoSep 30, 2026
  5. Phillip WoodOct 1, 2026
  6. Junio C HamanoOct 1, 2026
  7. Johannes SixtSep 30, 2026
  8. Junio C HamanoSep 30, 2026
  9. Johannes SixtSep 30, 2026
  10. Phillip WoodOct 1, 2026
  11. 0/2 checkout -m: recreate conflict labelsPhillip Wood, Oct 5, 2026
  12. 1/2 remove_branch_state: convert boolean argument to flagsPhillip Wood, Oct 5, 2026
  13. 2/2 merge: remember conflict labelsPhillip Wood, Oct 5, 2026
  14. Junio C HamanoOct 5, 2026
  15. Phillip WoodOct 6, 2026
  16. Junio C HamanoOct 5, 2026
  17. Phillip WoodOct 6, 2026
  18. Junio C HamanoOct 6, 2026
  19. Phillip WoodOct 7, 2026
  20. Johannes SixtOct 5, 2026
  21. Phillip WoodOct 5, 2026
  22. Junio C HamanoOct 5, 2026
  23. 0/2 checkout -m: recreate conflict labelsPhillip Wood, Oct 9, 2026
  24. 1/2 remove_branch_state: convert boolean argument to flagsPhillip Wood, Oct 9, 2026
  25. 2/2 merge: remember conflict labelsPhillip Wood, Oct 9, 2026
  26. Junio C HamanoOct 10, 2026
  27. Phillip WoodOct 12, 2026
  28. Junio C HamanoOct 12, 2026
  29. Phillip WoodOct 13, 2026
  30. Junio C HamanoOct 9, 2026
  31. 0/3 checkout -m: recreate conflict labelsPhillip Wood, Oct 13, 2026
  32. 1/3 remove_branch_state: convert boolean argument to flagsPhillip Wood, Oct 13, 2026
  33. 2/3 checkout -m <path>: cache merge settingsPhillip Wood, Oct 13, 2026
  34. 3/3 merge: remember conflict labelsPhillip Wood, Oct 13, 2026
  35. Junio C HamanoOct 13, 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.