[PATCH v5 1/4] stash: add --ours-label, --theirs-label, --base-label for apply
- From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 15, 2026, 11:19 UTC
- Message-ID
- <00d8920498fcc5dff2989f869fdaac2ed9f42d17.1773573553.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2234.v5.git.git.1773573553.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>
Allow callers of "git stash apply" to pass custom labels for conflict markers instead of the default "Updated upstream" and "Stashed changes". Document the new options and add a test.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> --- Documentation/git-stash.adoc | 11 ++++++++++- builtin/stash.c | 2 +- t/t3903-stash.sh | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-stash.adoc b/Documentation/git-stash.adoc index 235d57ddd8..43650a3c1a 100644 --- a/Documentation/git-stash.adoc +++ b/Documentation/git-stash.adoc @@ -12,7 +12,7 @@ git stash list [<log-options>] git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>] git stash drop [-q | --quiet] [<stash>] git stash pop [--index] [-q | --quiet] [<stash>] -git stash apply [--index] [-q | --quiet] [<stash>] +git stash apply [--index] [-q | --quiet] [--ours-label=<label>] [--theirs-label=<label>] [--base-label=<label>] [<stash>] git stash branch <branchname> [<stash>] git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet] [-u | --include-untracked] [-a | --all] [(-m | --message) <message>] @@ -197,6 +197,15 @@ the index's ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). +`--ours-label=<label>`:: +`--theirs-label=<label>`:: +`--base-label=<label>`:: + These options are only valid for the `apply` command. ++ +Use the given labels in conflict markers instead of the default +"Updated upstream", "Stashed changes", and "Stash base". +`--base-label` only has an effect with merge.conflictStyle=diff3. + `-k`:: `--keep-index`:: `--no-keep-index`:: diff --git a/builtin/stash.c b/builtin/stash.c index e79d612e57..252e4df3a9 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -44,7 +44,7 @@ #define BUILTIN_STASH_POP_USAGE \ N_("git stash pop [--index] [-q | --quiet] [<stash>]") #define BUILTIN_STASH_APPLY_USAGE \ - N_("git stash apply [--index] [-q | --quiet] [<stash>]") + N_("git stash apply [--index] [-q | --quiet] [--ours-label=<label>] [--theirs-label=<label>] [--base-label=<label>] [<stash>]") #define BUILTIN_STASH_BRANCH_USAGE \ N_("git stash branch <branchname> [<stash>]") #define BUILTIN_STASH_STORE_USAGE \ diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 70879941c2..dd47c1322a 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1666,6 +1666,24 @@ test_expect_success 'restore untracked files even when we hit conflicts' ' ) ' +test_expect_success 'apply with custom conflict labels' ' + git init conflict_labels && + ( + cd conflict_labels && + echo base >file && + git add file && + git commit -m base && + echo stashed >file && + git stash push -m "stashed" && + echo upstream >file && + git add file && + git commit -m upstream && + test_must_fail git stash apply --ours-label=UP --theirs-label=STASH && + grep "^<<<<<<< UP" file && + grep "^>>>>>>> STASH" file + ) +' + test_expect_success 'stash create reports a locked index' ' test_when_finished "rm -rf repo" && git init repo &&
-- gitgitgadget