* [PATCH 0/5] Advice on checkout dirty files
@ 2026-03-10 8:51 Arsh Srivastava via GitGitGadget
2026-03-10 8:51 ` [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width LorenzoPegorari via GitGitGadget
` (6 more replies)
0 siblings, 7 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
when they attempt to switch branches with local modifications that would be
overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save and
restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> "stashBeforeCheckout" to advice_setting[] and implement
> advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Arsh Srivastava (1):
advice: add stashBeforeCheckout advice for dirty branch switches
Junio C Hamano (1):
The 13th batch
K Jayatheerth (1):
repo: remove unnecessary variable shadow
LorenzoPegorari (2):
diff: handle ANSI escape codes in prefix when calculating diffstat
width
t4052: test for diffstat width when prefix contains ANSI escape codes
Documentation/RelNotes/2.54.0.adoc | 14 +++++++++++++
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++
advice.h | 2 ++
builtin/repo.c | 1 -
diff.c | 12 ++++-------
t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++
7 files changed, 84 insertions(+), 9 deletions(-)
base-commit: 3fe08b8fd1f7731edabeab8138547ec88d6407de
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
Pull-Request: https://github.com/git/git/pull/2233
--
gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
@ 2026-03-10 8:51 ` LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 2/5] t4052: test for diffstat width when prefix contains ANSI escape codes LorenzoPegorari via GitGitGadget
` (5 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: LorenzoPegorari via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava, LorenzoPegorari
From: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
The diffstat width is calculated by taking the terminal width and
incorrectly subtracting the `strlen()` of `line_prefix`, instead of the
actual display width of `line_prefix`, which may contain ANSI escape
codes (e.g., ANSI-colored strings in `log --graph --stat`).
Utilize the display width instead, obtained via `utf8_strnwidth()` with
the flag `skip_ansi`.
Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/diff.c b/diff.c
index 501648a5c4..da6e9e7f49 100644
--- a/diff.c
+++ b/diff.c
@@ -2756,7 +2756,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
count = i; /* where we can stop scanning in data->files[] */
/*
- * We have width = stat_width or term_columns() columns total.
+ * We have width = stat_width or term_columns() columns total minus the
+ * length of line_prefix skipping ANSI escape codes to get the display
+ * width (e.g., skip ANSI-colored strings in "log --graph --stat").
* We want a maximum of min(max_len, stat_name_width) for the name part.
* We want a maximum of min(max_change, stat_graph_width) for the +- part.
* We also need 1 for " " and 4 + decimal_width(max_change)
@@ -2783,14 +2785,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
* separators and this message, this message will "overflow"
* making the line longer than the maximum width.
*/
-
- /*
- * NEEDSWORK: line_prefix is often used for "log --graph" output
- * and contains ANSI-colored string. utf8_strnwidth() should be
- * used to correctly count the display width instead of strlen().
- */
if (options->stat_width == -1)
- width = term_columns() - strlen(line_prefix);
+ width = term_columns() - utf8_strnwidth(line_prefix, strlen(line_prefix), 1);
else
width = options->stat_width ? options->stat_width : 80;
number_width = decimal_width(max_change) > number_width ?
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH 2/5] t4052: test for diffstat width when prefix contains ANSI escape codes
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 8:51 ` [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width LorenzoPegorari via GitGitGadget
@ 2026-03-10 8:51 ` LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 3/5] repo: remove unnecessary variable shadow K Jayatheerth via GitGitGadget
` (4 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: LorenzoPegorari via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava, LorenzoPegorari
From: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Add test checking the calculation of the diffstat display width when the
`line_prefix`, which is text that goes before the diffstat, contains
ANSI escape codes.
This situation happens, for example, when `git log --stat --graph` is
executed:
* `--stat` will create a diffstat for each commit
* `--graph` will stuff `line_prefix` with the graph portion of the log,
which contains ANSI escape codes to color the text
Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
index 740bb97091..7c749062e2 100755
--- a/t/t4052-stat-output.sh
+++ b/t/t4052-stat-output.sh
@@ -413,4 +413,36 @@ test_expect_success 'merge --stat respects COLUMNS with long name' '
test_cmp expect actual
'
+# We want git-log to print only 1 commit containing a single branch graph and a
+# diffstat (the diffstat display width, when not manually set through the
+# option "--stat-width", will be automatically calculated).
+# The diffstat will be only one file, with a placeholder FILENAME, that, with
+# enough terminal display width, will contain the following line:
+# "<RED>|<RESET> ${FILENAME} | 0"
+# where "<RED>" and "<RESET>" are ANSI escape codes to color the text.
+# To calculate the minimium terminal display width MIN_TERM_WIDTH so that the
+# FILENAME in the diffstat will not be shortened, we take the FILENAME length
+# and add 9 to it.
+# To check if the diffstat width, when the line_prefix (the "<RED>|<RESET>" of
+# the graph) contains ANSI escape codes (the ANSI escape codes to color the
+# text), is calculated correctly, we:
+# 1. check if it contains the line defined before when using MIN_TERM_WIDTH
+# 2. check if it contains the line defined before, but with the FILENAME
+# shortened by only one character, when using MIN_TERM_WIDTH - 1
+
+test_expect_success 'diffstat where line_prefix contains ANSI escape codes is correct width' '
+ FILENAME="placeholder-text-placeholder-text" &&
+ FILENAME_TRIMMED="...eholder-text-placeholder-text" &&
+ MIN_TERM_WIDTH=$((${#FILENAME} + 9)) &&
+ test_config color.diff always &&
+ git commit --allow-empty --allow-empty-message &&
+ >${FILENAME} &&
+ git add ${FILENAME} &&
+ git commit --allow-empty-message &&
+ COLUMNS=$((MIN_TERM_WIDTH)) git log --graph --stat -n1 | test_decode_color >out &&
+ test_grep "<RED>|<RESET> ${FILENAME} | 0" out &&
+ COLUMNS=$((MIN_TERM_WIDTH - 1)) git log --graph --stat -n1 | test_decode_color >out &&
+ test_grep "<RED>|<RESET> ${FILENAME_TRIMMED} | 0" out
+'
+
test_done
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH 3/5] repo: remove unnecessary variable shadow
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 8:51 ` [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 2/5] t4052: test for diffstat width when prefix contains ANSI escape codes LorenzoPegorari via GitGitGadget
@ 2026-03-10 8:51 ` K Jayatheerth via GitGitGadget
2026-03-10 8:51 ` [PATCH 4/5] The 13th batch Junio C Hamano via GitGitGadget
` (3 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: K Jayatheerth via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava, K Jayatheerth
From: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Avoid redeclaring `entry` inside the conditional block, removing
unnecessary variable shadowing and improving code clarity without
changing behavior.
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Acked-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/repo.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/builtin/repo.c b/builtin/repo.c
index f943be7451..fae1141cff 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -445,7 +445,6 @@ static void stats_table_print_structure(const struct stats_table *table)
const char *unit = "";
if (entry) {
- struct stats_table_entry *entry = item->util;
value = entry->value;
if (entry->unit)
unit = entry->unit;
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH 4/5] The 13th batch
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-10 8:51 ` [PATCH 3/5] repo: remove unnecessary variable shadow K Jayatheerth via GitGitGadget
@ 2026-03-10 8:51 ` Junio C Hamano via GitGitGadget
2026-03-10 8:51 ` [PATCH 5/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (2 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Junio C Hamano via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava, Junio C Hamano
From: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/RelNotes/2.54.0.adoc | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/RelNotes/2.54.0.adoc b/Documentation/RelNotes/2.54.0.adoc
index fa6e42f3bb..ed5231f82c 100644
--- a/Documentation/RelNotes/2.54.0.adoc
+++ b/Documentation/RelNotes/2.54.0.adoc
@@ -60,6 +60,10 @@ UI, Workflows & Features
* "git config list" is taught to show the values interpreted for
specific type with "--type=<X>" option.
+ * "git add <submodule>" has been taught to honor
+ submodule.<name>.ignore that is set to "all" (and requires "git add
+ -f" to override it).
+
Performance, Internal Implementation, Development Support etc.
--------------------------------------------------------------
@@ -143,6 +147,11 @@ Performance, Internal Implementation, Development Support etc.
were kept track of by a single global variable in-core, which has
been corrected by moving it to per-repository data structure.
+ * Use the hook API to replace ad-hoc invocation of hook scripts via
+ the run_command() API.
+
+ * Code refactoring around refs-for-each-* API functions.
+
Fixes since v2.53
-----------------
@@ -234,6 +243,10 @@ Fixes since v2.53
to access pack data by "fsck" has been updated to avoid this.
(merge 13eb65d366 ps/fsck-stream-from-the-right-object-instance later to maint).
+ * "git log --graph --stat" did not count the display width of colored
+ graph part of its own output correctly, which has been corrected.
+ (merge 064b869efc lp/diff-stat-utf8-display-width-fix later to maint).
+
* Other code cleanup, docfix, build fix, etc.
(merge d79fff4a11 jk/remote-tracking-ref-leakfix later to maint).
(merge 7a747f972d dd/t5403-modernise later to maint).
@@ -264,3 +277,4 @@ Fixes since v2.53
(merge ed84bc1c0d kh/doc-patch-id-4 later to maint).
(merge 7451864bfa sc/pack-redundant-leakfix later to maint).
(merge f87593ab1a cx/fetch-display-ubfix later to maint).
+ (merge a66c8c7f91 jk/repo-structure-cleanup later to maint).
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH 5/5] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (3 preceding siblings ...)
2026-03-10 8:51 ` [PATCH 4/5] The 13th batch Junio C Hamano via GitGitGadget
@ 2026-03-10 8:51 ` Arsh Srivastava via GitGitGadget
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 8:51 UTC (permalink / raw)
To: git; +Cc: Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
+ stashBeforeCheckout::
+ Shown when the user attempts to switch branches but has
+ local modifications that would be overwritten by the
+ operation, to suggest using linkgit:git-stash[1] to
+ save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
+ [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
+
+void advise_on_checkout_dirty_files(struct string_list *file_list)
+{
+ struct string_list_item *item;
+
+ if (!file_list->nr)
+ return;
+
+ fprintf(stderr, _("The following files have local modifications that would\n"
+ "be overwritten by switching branches:\n"));
+ for_each_string_list_item(item, file_list)
+ fprintf(stderr, "\t%s\n", item->string);
+
+ advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
+ _("You can save your local changes before switching by running:\n"
+ "\n"
+ "\tgit stash push\n"
+ "\n"
+ "Then restore them after switching with:\n"
+ "\n"
+ "\tgit stash pop\n"
+ "\n"
+ "Or to discard your local changes, use:\n"
+ "\n"
+ "\tgit checkout -- <file>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
+ ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
+void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (4 preceding siblings ...)
2026-03-10 8:51 ` [PATCH 5/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-10 10:33 ` Phillip Wood
2026-03-10 10:42 ` Arsh Srivastava
2026-03-10 13:36 ` Junio C Hamano
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
6 siblings, 2 replies; 62+ messages in thread
From: Phillip Wood @ 2026-03-10 10:33 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget, git; +Cc: Arsh Srivastava
Hi Arsh
On 10/03/2026 08:51, Arsh Srivastava via GitGitGadget wrote:
> This is my submission for microproject [GSOC]
>
> This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> when they attempt to switch branches with local modifications that would be
> overwritten by the operation.
If the intent is for the user to carry over the changes to the new
branch then recommending "git checkout -m" might be more convenient
rather than having to stash, checkout and unstash as three separate steps.
Something seems to have gone awry with your branch as there are other
patches in this series. You should rebase your branch onto the upstream
master branch with
git rebase --onto origin/master HEAD^
and then when you push it double check how many commits there are in the
summary of the pull request before submitting.
Thanks
Phillip
> The new advice follows the same patterns established by existing advice
> functions such as advise_on_updating_sparse_paths(). When triggered, it
> lists the affected files and suggests using git stash push/pop to save and
> restore local changes.
>
> The advice can be silenced with:
>
> git config set advice.stashBeforeCheckout false
>
> Changes:
>
>> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
>> "stashBeforeCheckout" to advice_setting[] and implement
>> advise_on_checkout_dirty_files() function
>> Documentation/config/advice.adoc: document the new advice key
>
> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>
> Arsh Srivastava (1):
> advice: add stashBeforeCheckout advice for dirty branch switches
>
> Junio C Hamano (1):
> The 13th batch
>
> K Jayatheerth (1):
> repo: remove unnecessary variable shadow
>
> LorenzoPegorari (2):
> diff: handle ANSI escape codes in prefix when calculating diffstat
> width
> t4052: test for diffstat width when prefix contains ANSI escape codes
>
> Documentation/RelNotes/2.54.0.adoc | 14 +++++++++++++
> Documentation/config/advice.adoc | 5 +++++
> advice.c | 27 +++++++++++++++++++++++++
> advice.h | 2 ++
> builtin/repo.c | 1 -
> diff.c | 12 ++++-------
> t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++
> 7 files changed, 84 insertions(+), 9 deletions(-)
>
>
> base-commit: 3fe08b8fd1f7731edabeab8138547ec88d6407de
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
> Pull-Request: https://github.com/git/git/pull/2233
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
@ 2026-03-10 10:42 ` Arsh Srivastava
2026-03-10 10:45 ` Arsh Srivastava
2026-03-10 13:36 ` Junio C Hamano
1 sibling, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 10:42 UTC (permalink / raw)
To: phillip.wood; +Cc: Arsh Srivastava via GitGitGadget, git
Thank you so much for the advice I will
> rebase my file’s pointer head
And just wanted to know what do you recommend should be my changed
approach for me over this pr to make that function useful
On Tue, 10 Mar 2026 at 4:03 PM, Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Hi Arsh
>
> On 10/03/2026 08:51, Arsh Srivastava via GitGitGadget wrote:
> > This is my submission for microproject [GSOC]
> >
> > This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> > when they attempt to switch branches with local modifications that would be
> > overwritten by the operation.
>
> If the intent is for the user to carry over the changes to the new
> branch then recommending "git checkout -m" might be more convenient
> rather than having to stash, checkout and unstash as three separate steps.
>
> Something seems to have gone awry with your branch as there are other
> patches in this series. You should rebase your branch onto the upstream
> master branch with
>
> git rebase --onto origin/master HEAD^
>
> and then when you push it double check how many commits there are in the
> summary of the pull request before submitting.
>
> Thanks
>
> Phillip
>
> > The new advice follows the same patterns established by existing advice
> > functions such as advise_on_updating_sparse_paths(). When triggered, it
> > lists the affected files and suggests using git stash push/pop to save and
> > restore local changes.
> >
> > The advice can be silenced with:
> >
> > git config set advice.stashBeforeCheckout false
> >
> > Changes:
> >
> >> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> >> "stashBeforeCheckout" to advice_setting[] and implement
> >> advise_on_checkout_dirty_files() function
> >> Documentation/config/advice.adoc: document the new advice key
> >
> > Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
> >
> > Arsh Srivastava (1):
> > advice: add stashBeforeCheckout advice for dirty branch switches
> >
> > Junio C Hamano (1):
> > The 13th batch
> >
> > K Jayatheerth (1):
> > repo: remove unnecessary variable shadow
> >
> > LorenzoPegorari (2):
> > diff: handle ANSI escape codes in prefix when calculating diffstat
> > width
> > t4052: test for diffstat width when prefix contains ANSI escape codes
> >
> > Documentation/RelNotes/2.54.0.adoc | 14 +++++++++++++
> > Documentation/config/advice.adoc | 5 +++++
> > advice.c | 27 +++++++++++++++++++++++++
> > advice.h | 2 ++
> > builtin/repo.c | 1 -
> > diff.c | 12 ++++-------
> > t/t4052-stat-output.sh | 32 ++++++++++++++++++++++++++++++
> > 7 files changed, 84 insertions(+), 9 deletions(-)
> >
> >
> > base-commit: 3fe08b8fd1f7731edabeab8138547ec88d6407de
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v1
> > Pull-Request: https://github.com/git/git/pull/2233
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 10:42 ` Arsh Srivastava
@ 2026-03-10 10:45 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 10:45 UTC (permalink / raw)
To: phillip.wood; +Cc: Arsh Srivastava via GitGitGadget, git
Hi,
Thank you for the feedback!
That's a great point. Using "git checkout -m" is indeed more convenient
when the user wants to carry their changes over to the new branch, as it
merges the local modifications into the new branch in a single step
rather than requiring stash, checkout, and unstash separately.
I will update the advice message to mention "git checkout -m" as the
primary suggestion when the intent is to carry changes over, and keep
git stash push/pop as an alternative for when the user wants to
temporarily set changes aside.
Will send a v2 shortly.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (5 preceding siblings ...)
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
@ 2026-03-10 10:59 ` Arsh Srivastava via GitGitGadget
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
` (3 more replies)
6 siblings, 4 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 10:59 UTC (permalink / raw)
To: git; +Cc: Phillip Wood, Arsh Srivastava, Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help
users when they attempt to switch branches with local modifications that
would be overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save
and restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> "stashBeforeCheckout" to advice_setting[] and implement
> advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v2
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v1:
1: 0ed992956e < -: ---------- diff: handle ANSI escape codes in prefix when calculating diffstat width
2: c70043a2c0 < -: ---------- t4052: test for diffstat width when prefix contains ANSI escape codes
3: 185356a454 < -: ---------- repo: remove unnecessary variable shadow
4: acebdd714b < -: ---------- The 13th batch
5: 9ec447e3cb = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
+ stashBeforeCheckout::
+ Shown when the user attempts to switch branches but has
+ local modifications that would be overwritten by the
+ operation, to suggest using linkgit:git-stash[1] to
+ save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
+ [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
+
+void advise_on_checkout_dirty_files(struct string_list *file_list)
+{
+ struct string_list_item *item;
+
+ if (!file_list->nr)
+ return;
+
+ fprintf(stderr, _("The following files have local modifications that would\n"
+ "be overwritten by switching branches:\n"));
+ for_each_string_list_item(item, file_list)
+ fprintf(stderr, "\t%s\n", item->string);
+
+ advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
+ _("You can save your local changes before switching by running:\n"
+ "\n"
+ "\tgit stash push\n"
+ "\n"
+ "Then restore them after switching with:\n"
+ "\n"
+ "\tgit stash pop\n"
+ "\n"
+ "Or to discard your local changes, use:\n"
+ "\n"
+ "\tgit checkout -- <file>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
+ ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
+void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
@ 2026-03-10 11:04 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 11:04 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget; +Cc: git, Phillip Wood
I have as you mentioned changed
> Rebased my files pointer
> Changed advice to git checkout -m
Thank you
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 16:33, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> I have as you mentioned changed
> > Rebased my files pointer
> > Changed advice to git checkout -m
> Thank you
>
> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> On Tue, 10 Mar 2026 at 4:29 PM, Arsh Srivastava via GitGitGadget <gitgitgadget@gmail.com> wrote:
>>
>> From: Arsh Srivastava <arshsrivastava00@gmail.com>
>>
>> Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
>> when they attempt to switch branches with local modifications that
>> would be overwritten by the operation.
>>
>> This includes:
>> > New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
>> > Corresponding "stashBeforeCheckout" entry in advice_setting[]
>> > New advise_on_checkout_dirty_files() function that lists the
>> affected files and suggests using git stash push/pop
>> > Documentation entry in Documentation/config/advice.txt
>>
>> The advice follows existing patterns established by
>> advise_on_updating_sparse_paths() and can be silenced with:
>>
>> git config set advice.stashBeforeCheckout false
>>
>> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>> ---
>> Advice on checkout dirty files
>>
>> This is my submission for microproject [GSOC]
>>
>> This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help
>> users when they attempt to switch branches with local modifications that
>> would be overwritten by the operation.
>>
>> The new advice follows the same patterns established by existing advice
>> functions such as advise_on_updating_sparse_paths(). When triggered, it
>> lists the affected files and suggests using git stash push/pop to save
>> and restore local changes.
>>
>> The advice can be silenced with:
>>
>> git config set advice.stashBeforeCheckout false
>>
>> Changes:
>>
>> > advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
>> > "stashBeforeCheckout" to advice_setting[] and implement
>> > advise_on_checkout_dirty_files() function
>> > Documentation/config/advice.adoc: document the new advice key
>>
>> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>>
>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v2
>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v2
>> Pull-Request: https://github.com/git/git/pull/2233
>>
>> Range-diff vs v1:
>>
>> 1: 0ed992956e < -: ---------- diff: handle ANSI escape codes in prefix when calculating diffstat width
>> 2: c70043a2c0 < -: ---------- t4052: test for diffstat width when prefix contains ANSI escape codes
>> 3: 185356a454 < -: ---------- repo: remove unnecessary variable shadow
>> 4: acebdd714b < -: ---------- The 13th batch
>> 5: 9ec447e3cb = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
>>
>>
>> Documentation/config/advice.adoc | 5 +++++
>> advice.c | 27 +++++++++++++++++++++++++++
>> advice.h | 2 ++
>> 3 files changed, 34 insertions(+)
>>
>> diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
>> index 257db58918..8752e05636 100644
>> --- a/Documentation/config/advice.adoc
>> +++ b/Documentation/config/advice.adoc
>> @@ -126,6 +126,11 @@ all advice messages.
>> Shown when a sparse index is expanded to a full index, which is likely
>> due to an unexpected set of files existing outside of the
>> sparse-checkout.
>> + stashBeforeCheckout::
>> + Shown when the user attempts to switch branches but has
>> + local modifications that would be overwritten by the
>> + operation, to suggest using linkgit:git-stash[1] to
>> + save changes before switching.
>> statusAheadBehind::
>> Shown when linkgit:git-status[1] computes the ahead/behind
>> counts for a local ref compared to its remote tracking ref,
>> diff --git a/advice.c b/advice.c
>> index 0018501b7b..e1264f525c 100644
>> --- a/advice.c
>> +++ b/advice.c
>> @@ -81,6 +81,7 @@ static struct {
>> [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
>> [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
>> [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
>> + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
>> [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
>> [ADVICE_STATUS_HINTS] = { "statusHints" },
>> [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
>> @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
>> "* Use \"git add --sparse <paths>\" to update the index\n"
>> "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
>> }
>> +
>> +void advise_on_checkout_dirty_files(struct string_list *file_list)
>> +{
>> + struct string_list_item *item;
>> +
>> + if (!file_list->nr)
>> + return;
>> +
>> + fprintf(stderr, _("The following files have local modifications that would\n"
>> + "be overwritten by switching branches:\n"));
>> + for_each_string_list_item(item, file_list)
>> + fprintf(stderr, "\t%s\n", item->string);
>> +
>> + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
>> + _("You can save your local changes before switching by running:\n"
>> + "\n"
>> + "\tgit stash push\n"
>> + "\n"
>> + "Then restore them after switching with:\n"
>> + "\n"
>> + "\tgit stash pop\n"
>> + "\n"
>> + "Or to discard your local changes, use:\n"
>> + "\n"
>> + "\tgit checkout -- <file>"));
>> +}
>> diff --git a/advice.h b/advice.h
>> index 8def280688..c035b5d8e3 100644
>> --- a/advice.h
>> +++ b/advice.h
>> @@ -48,6 +48,7 @@ enum advice_type {
>> ADVICE_SET_UPSTREAM_FAILURE,
>> ADVICE_SKIPPED_CHERRY_PICKS,
>> ADVICE_SPARSE_INDEX_EXPANDED,
>> + ADVICE_STASH_BEFORE_CHECKOUT,
>> ADVICE_STATUS_AHEAD_BEHIND_WARNING,
>> ADVICE_STATUS_HINTS,
>> ADVICE_STATUS_U_OPTION,
>> @@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
>> void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
>> void detach_advice(const char *new_name);
>> void advise_on_moving_dirty_path(struct string_list *pathspec_list);
>> +void advise_on_checkout_dirty_files(struct string_list *file_list);
>>
>> #endif /* ADVICE_H */
>>
>> base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
>> --
>> gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
@ 2026-03-10 13:16 ` Patrick Steinhardt
2026-03-10 13:36 ` Arsh Srivastava
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 14:31 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Karthik Nayak
3 siblings, 1 reply; 62+ messages in thread
From: Patrick Steinhardt @ 2026-03-10 13:16 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget; +Cc: git, Phillip Wood, Arsh Srivastava
On Tue, Mar 10, 2026 at 10:59:24AM +0000, Arsh Srivastava via GitGitGadget wrote:
> diff --git a/advice.c b/advice.c
> index 0018501b7b..e1264f525c 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -81,6 +81,7 @@ static struct {
> [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> [ADVICE_STATUS_HINTS] = { "statusHints" },
> [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> "* Use \"git add --sparse <paths>\" to update the index\n"
> "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> }
> +
> +void advise_on_checkout_dirty_files(struct string_list *file_list)
Huh. So this patch wires up a new function and advice, but we don't ever
seem to use it. Am I missing something?
Patrick
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v3 0/2] Advice on checkout dirty files
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
2026-03-10 13:16 ` Patrick Steinhardt
@ 2026-03-10 13:28 ` Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (2 more replies)
2026-03-10 14:31 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Karthik Nayak
3 siblings, 3 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 13:28 UTC (permalink / raw)
To: git; +Cc: Phillip Wood, Arsh Srivastava, Arsh Srivastava
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
when they attempt to switch branches with local modifications that would be
overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save and
restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> "stashBeforeCheckout" to advice_setting[] and implement
> advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Arsh Srivastava (2):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
Documentation/config/advice.adoc | 5 +++++
advice.c | 20 ++++++++++++++++++++
advice.h | 2 ++
3 files changed, 27 insertions(+)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v3
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v2:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
-: ---------- > 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
--
gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
@ 2026-03-10 13:28 ` Arsh Srivastava via GitGitGadget
2026-03-10 13:43 ` Arsh Srivastava
2026-03-10 13:28 ` [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 13:28 UTC (permalink / raw)
To: git; +Cc: Phillip Wood, Arsh Srivastava, Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
+ stashBeforeCheckout::
+ Shown when the user attempts to switch branches but has
+ local modifications that would be overwritten by the
+ operation, to suggest using linkgit:git-stash[1] to
+ save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
+ [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
+
+void advise_on_checkout_dirty_files(struct string_list *file_list)
+{
+ struct string_list_item *item;
+
+ if (!file_list->nr)
+ return;
+
+ fprintf(stderr, _("The following files have local modifications that would\n"
+ "be overwritten by switching branches:\n"));
+ for_each_string_list_item(item, file_list)
+ fprintf(stderr, "\t%s\n", item->string);
+
+ advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
+ _("You can save your local changes before switching by running:\n"
+ "\n"
+ "\tgit stash push\n"
+ "\n"
+ "Then restore them after switching with:\n"
+ "\n"
+ "\tgit stash pop\n"
+ "\n"
+ "Or to discard your local changes, use:\n"
+ "\n"
+ "\tgit checkout -- <file>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
+ ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
+void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-10 13:28 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-10 13:28 UTC (permalink / raw)
To: git; +Cc: Phillip Wood, Arsh Srivastava, Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes
over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement
advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
advice.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/advice.c b/advice.c
index e1264f525c..ba290d3760 100644
--- a/advice.c
+++ b/advice.c
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)
fprintf(stderr, "\t%s\n", item->string);
advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
- _("You can save your local changes before switching by running:\n"
+ _("To carry your local changes over to the new branch, use:\n"
"\n"
- "\tgit stash push\n"
- "\n"
- "Then restore them after switching with:\n"
- "\n"
- "\tgit stash pop\n"
- "\n"
- "Or to discard your local changes, use:\n"
- "\n"
- "\tgit checkout -- <file>"));
+ "\tgit checkout -m <branch>\n"
+ ));
}
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
2026-03-10 10:42 ` Arsh Srivastava
@ 2026-03-10 13:36 ` Junio C Hamano
2026-03-10 13:40 ` Arsh Srivastava
1 sibling, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-10 13:36 UTC (permalink / raw)
To: Phillip Wood; +Cc: Arsh Srivastava via GitGitGadget, git, Arsh Srivastava
Phillip Wood <phillip.wood123@gmail.com> writes:
> If the intent is for the user to carry over the changes to the new
> branch then recommending "git checkout -m" might be more convenient
> rather than having to stash, checkout and unstash as three separate steps.
I personally would not recommend pushing "-m" to new people without
explaining its ramifications, though.
If "git stash pop" fails while a commit different from the original
is checked out, the working tree will get conflicts for you to
resolve, and that is the same as "git checkout -m". But the
conflict may turn out to be too complex that you might not be able
to cleanly resolve.
With a "git stash pop" that gets interrupted by a conflict, the
stash entry is not removed from the stash, so there is a clean
recourse to "git reset --hard" away the conflict and attempting to
unstash (either to the same commit or to a different base).
With "git checkout -m", on the other hand, there is no such
recourse. The conflicted working tree with the unmerged index is
all you get, and you get only a single chance to resolve it
correctly.
So...
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 13:16 ` Patrick Steinhardt
@ 2026-03-10 13:36 ` Arsh Srivastava
2026-03-10 14:24 ` Patrick Steinhardt
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 13:36 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
Thank you so much for looking into my PR and i believe advice.h is
used in the add.c file. And advice really helps young developers
understand what's wrong in their files because navigating git and
trying to find solutions is very difficult, causing them to go to ai
models making them copy pasting machines.
On Tue, 10 Mar 2026 at 18:46, Patrick Steinhardt <ps@pks.im> wrote:
>
> On Tue, Mar 10, 2026 at 10:59:24AM +0000, Arsh Srivastava via GitGitGadget wrote:
> > diff --git a/advice.c b/advice.c
> > index 0018501b7b..e1264f525c 100644
> > --- a/advice.c
> > +++ b/advice.c
> > @@ -81,6 +81,7 @@ static struct {
> > [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> > [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> > [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> > + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> > [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> > [ADVICE_STATUS_HINTS] = { "statusHints" },
> > [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> > @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> > "* Use \"git add --sparse <paths>\" to update the index\n"
> > "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> > }
> > +
> > +void advise_on_checkout_dirty_files(struct string_list *file_list)
>
> Huh. So this patch wires up a new function and advice, but we don't ever
> seem to use it. Am I missing something?
>
> Patrick
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 13:36 ` Junio C Hamano
@ 2026-03-10 13:40 ` Arsh Srivastava
2026-03-10 15:40 ` Junio C Hamano
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 13:40 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Phillip Wood, Arsh Srivastava via GitGitGadget, git
As per the recommendation of Phillip Wood <phillip.wood123@gmail.com>
I have changed my files and added git checkout -m after understanding
its significance :)
On Tue, 10 Mar 2026 at 19:06, Junio C Hamano <gitster@pobox.com> wrote:
>
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
> > If the intent is for the user to carry over the changes to the new
> > branch then recommending "git checkout -m" might be more convenient
> > rather than having to stash, checkout and unstash as three separate steps.
>
> I personally would not recommend pushing "-m" to new people without
> explaining its ramifications, though.
>
> If "git stash pop" fails while a commit different from the original
> is checked out, the working tree will get conflicts for you to
> resolve, and that is the same as "git checkout -m". But the
> conflict may turn out to be too complex that you might not be able
> to cleanly resolve.
>
> With a "git stash pop" that gets interrupted by a conflict, the
> stash entry is not removed from the stash, so there is a clean
> recourse to "git reset --hard" away the conflict and attempting to
> unstash (either to the same commit or to a different base).
>
> With "git checkout -m", on the other hand, there is no such
> recourse. The conflicted working tree with the unmerged index is
> all you get, and you get only a single chance to resolve it
> correctly.
>
> So...
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-10 13:43 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 13:43 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget; +Cc: git, Phillip Wood
Thank you so much for looking into my PR and i believe
> advice.h is used in the add.c file.
> And advice really helps young developers
understand what's wrong in their files because navigating git and
trying to find solutions is very difficult,
> causing them to go to ai models making them copy pasting machines.
On Tue, 10 Mar 2026 at 18:59, Arsh Srivastava via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
> when they attempt to switch branches with local modifications that
> would be overwritten by the operation.
>
> This includes:
> > New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> > Corresponding "stashBeforeCheckout" entry in advice_setting[]
> > New advise_on_checkout_dirty_files() function that lists the
> affected files and suggests using git stash push/pop
> > Documentation entry in Documentation/config/advice.txt
>
> The advice follows existing patterns established by
> advise_on_updating_sparse_paths() and can be silenced with:
>
> git config set advice.stashBeforeCheckout false
>
> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
> ---
> Documentation/config/advice.adoc | 5 +++++
> advice.c | 27 +++++++++++++++++++++++++++
> advice.h | 2 ++
> 3 files changed, 34 insertions(+)
>
> diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
> index 257db58918..8752e05636 100644
> --- a/Documentation/config/advice.adoc
> +++ b/Documentation/config/advice.adoc
> @@ -126,6 +126,11 @@ all advice messages.
> Shown when a sparse index is expanded to a full index, which is likely
> due to an unexpected set of files existing outside of the
> sparse-checkout.
> + stashBeforeCheckout::
> + Shown when the user attempts to switch branches but has
> + local modifications that would be overwritten by the
> + operation, to suggest using linkgit:git-stash[1] to
> + save changes before switching.
> statusAheadBehind::
> Shown when linkgit:git-status[1] computes the ahead/behind
> counts for a local ref compared to its remote tracking ref,
> diff --git a/advice.c b/advice.c
> index 0018501b7b..e1264f525c 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -81,6 +81,7 @@ static struct {
> [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> [ADVICE_STATUS_HINTS] = { "statusHints" },
> [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> "* Use \"git add --sparse <paths>\" to update the index\n"
> "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> }
> +
> +void advise_on_checkout_dirty_files(struct string_list *file_list)
> +{
> + struct string_list_item *item;
> +
> + if (!file_list->nr)
> + return;
> +
> + fprintf(stderr, _("The following files have local modifications that would\n"
> + "be overwritten by switching branches:\n"));
> + for_each_string_list_item(item, file_list)
> + fprintf(stderr, "\t%s\n", item->string);
> +
> + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
> + _("You can save your local changes before switching by running:\n"
> + "\n"
> + "\tgit stash push\n"
> + "\n"
> + "Then restore them after switching with:\n"
> + "\n"
> + "\tgit stash pop\n"
> + "\n"
> + "Or to discard your local changes, use:\n"
> + "\n"
> + "\tgit checkout -- <file>"));
> +}
> diff --git a/advice.h b/advice.h
> index 8def280688..c035b5d8e3 100644
> --- a/advice.h
> +++ b/advice.h
> @@ -48,6 +48,7 @@ enum advice_type {
> ADVICE_SET_UPSTREAM_FAILURE,
> ADVICE_SKIPPED_CHERRY_PICKS,
> ADVICE_SPARSE_INDEX_EXPANDED,
> + ADVICE_STASH_BEFORE_CHECKOUT,
> ADVICE_STATUS_AHEAD_BEHIND_WARNING,
> ADVICE_STATUS_HINTS,
> ADVICE_STATUS_U_OPTION,
> @@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
> void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
> void detach_advice(const char *new_name);
> void advise_on_moving_dirty_path(struct string_list *pathspec_list);
> +void advise_on_checkout_dirty_files(struct string_list *file_list);
>
> #endif /* ADVICE_H */
> --
> gitgitgadget
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 13:36 ` Arsh Srivastava
@ 2026-03-10 14:24 ` Patrick Steinhardt
0 siblings, 0 replies; 62+ messages in thread
From: Patrick Steinhardt @ 2026-03-10 14:24 UTC (permalink / raw)
To: Arsh Srivastava; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
On Tue, Mar 10, 2026 at 07:06:39PM +0530, Arsh Srivastava wrote:
> On Tue, 10 Mar 2026 at 18:46, Patrick Steinhardt <ps@pks.im> wrote:
> > On Tue, Mar 10, 2026 at 10:59:24AM +0000, Arsh Srivastava via GitGitGadget wrote:
> > > diff --git a/advice.c b/advice.c
> > > index 0018501b7b..e1264f525c 100644
> > > --- a/advice.c
> > > +++ b/advice.c
> > > @@ -81,6 +81,7 @@ static struct {
> > > [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> > > [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> > > [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> > > + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> > > [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> > > [ADVICE_STATUS_HINTS] = { "statusHints" },
> > > [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> > > @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> > > "* Use \"git add --sparse <paths>\" to update the index\n"
> > > "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> > > }
> > > +
> > > +void advise_on_checkout_dirty_files(struct string_list *file_list)
> >
> > Huh. So this patch wires up a new function and advice, but we don't ever
> > seem to use it. Am I missing something?
>
> Thank you so much for looking into my PR and i believe advice.h is
> used in the add.c file. And advice really helps young developers
> understand what's wrong in their files because navigating git and
> trying to find solutions is very difficult, causing them to go to ai
> models making them copy pasting machines.
(Please note that we prefer bottom posting on this mailing list, where
your answer goes below the quoted context.)
It is used in "add.c", but not magically so. The function that you have
introduced is the only site that uses the new advice, but the function
is never called as far as I can see. So ultimately, the proposed change
does not have any effect on the user-observable behaviour.
Patrick
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
@ 2026-03-10 14:31 ` Karthik Nayak
2026-03-10 14:37 ` Arsh Srivastava
3 siblings, 1 reply; 62+ messages in thread
From: Karthik Nayak @ 2026-03-10 14:31 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget, git; +Cc: Phillip Wood, Arsh Srivastava
[-- Attachment #1: Type: text/plain, Size: 4460 bytes --]
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
> when they attempt to switch branches with local modifications that
> would be overwritten by the operation.
>
> This includes:
>> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
>> Corresponding "stashBeforeCheckout" entry in advice_setting[]
>> New advise_on_checkout_dirty_files() function that lists the
> affected files and suggests using git stash push/pop
>> Documentation entry in Documentation/config/advice.txt
>
Nit: Did you mean to add bullet point here? '>' is generally used to
quote text. Perhaps use '-' or '*'.
[snip]
>
> Documentation/config/advice.adoc | 5 +++++
> advice.c | 27 +++++++++++++++++++++++++++
> advice.h | 2 ++
> 3 files changed, 34 insertions(+)
>
Hmm. Shouldn't there be changes which actually call the newly introduced
function? Also shouldn't there be tests added?
> diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
> index 257db58918..8752e05636 100644
> --- a/Documentation/config/advice.adoc
> +++ b/Documentation/config/advice.adoc
> @@ -126,6 +126,11 @@ all advice messages.
> Shown when a sparse index is expanded to a full index, which is likely
> due to an unexpected set of files existing outside of the
> sparse-checkout.
> + stashBeforeCheckout::
> + Shown when the user attempts to switch branches but has
> + local modifications that would be overwritten by the
> + operation, to suggest using linkgit:git-stash[1] to
> + save changes before switching.
Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
In one of my repos:
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
❯ echo "aldjf" >> LICENSE
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: LICENSE
no changes added to commit (use "git add" and/or "git commit -a")
❯ git checkout 0-1-stable
error: Your local changes to the following files would be overwritten
by checkout:
LICENSE
Please commit your changes or stash them before you switch branches.
Aborting
So won't this simply be duplicating the same message?
> statusAheadBehind::
> Shown when linkgit:git-status[1] computes the ahead/behind
> counts for a local ref compared to its remote tracking ref,
> diff --git a/advice.c b/advice.c
> index 0018501b7b..e1264f525c 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -81,6 +81,7 @@ static struct {
> [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> [ADVICE_STATUS_HINTS] = { "statusHints" },
> [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> "* Use \"git add --sparse <paths>\" to update the index\n"
> "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> }
> +
> +void advise_on_checkout_dirty_files(struct string_list *file_list)
> +{
> + struct string_list_item *item;
> +
> + if (!file_list->nr)
> + return;
> +
> + fprintf(stderr, _("The following files have local modifications that would\n"
> + "be overwritten by switching branches:\n"));
> + for_each_string_list_item(item, file_list)
> + fprintf(stderr, "\t%s\n", item->string);
> +
> + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
> + _("You can save your local changes before switching by running:\n"
> + "\n"
> + "\tgit stash push\n"
> + "\n"
> + "Then restore them after switching with:\n"
> + "\n"
> + "\tgit stash pop\n"
> + "\n"
> + "Or to discard your local changes, use:\n"
> + "\n"
> + "\tgit checkout -- <file>"));
> +}
This doesn't seem to be formatted with tabs.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 14:31 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Karthik Nayak
@ 2026-03-10 14:37 ` Arsh Srivastava
2026-03-10 14:40 ` Arsh Srivastava
` (2 more replies)
0 siblings, 3 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 14:37 UTC (permalink / raw)
To: Karthik Nayak; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
branch switches
Karthik Nayak <karthik.188@gmail.com> writes:
> Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> So won't this simply be duplicating the same message?
Thank you for the detailed review. You are correct, the existing message
in unpack-trees.c already handles this case and my patch duplicates it.
I also acknowledge the other issues raised:
- The newly introduced function was never called anywhere in the codebase
- No tests were added
- The bullet points in the commit message used '>' instead of '-' or '*'
- The advice message was not formatted with tabs
Rather than duplicating the existing behaviour, I think the better
approach would be to enhance the existing message in unpack-trees.c to
also mention 'git checkout -m' as an option for users who want to carry
their local changes over to the new branch, since the current message
only says "commit or stash" without mentioning that option.
I will rework the patch in that direction and send a v4.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 20:01, Karthik Nayak <karthik.188@gmail.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Arsh Srivastava <arshsrivastava00@gmail.com>
> >
> > Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
> > when they attempt to switch branches with local modifications that
> > would be overwritten by the operation.
> >
> > This includes:
> >> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> >> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> >> New advise_on_checkout_dirty_files() function that lists the
> > affected files and suggests using git stash push/pop
> >> Documentation entry in Documentation/config/advice.txt
> >
>
> Nit: Did you mean to add bullet point here? '>' is generally used to
> quote text. Perhaps use '-' or '*'.
>
> [snip]
>
> >
> > Documentation/config/advice.adoc | 5 +++++
> > advice.c | 27 +++++++++++++++++++++++++++
> > advice.h | 2 ++
> > 3 files changed, 34 insertions(+)
> >
>
> Hmm. Shouldn't there be changes which actually call the newly introduced
> function? Also shouldn't there be tests added?
>
> > diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
> > index 257db58918..8752e05636 100644
> > --- a/Documentation/config/advice.adoc
> > +++ b/Documentation/config/advice.adoc
> > @@ -126,6 +126,11 @@ all advice messages.
> > Shown when a sparse index is expanded to a full index, which is likely
> > due to an unexpected set of files existing outside of the
> > sparse-checkout.
> > + stashBeforeCheckout::
> > + Shown when the user attempts to switch branches but has
> > + local modifications that would be overwritten by the
> > + operation, to suggest using linkgit:git-stash[1] to
> > + save changes before switching.
>
> Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
>
> In one of my repos:
>
> ❯ git status
> On branch master
> Your branch is up to date with 'origin/master'.
>
> nothing to commit, working tree clean
>
> ❯ echo "aldjf" >> LICENSE
>
> ❯ git status
> On branch master
> Your branch is up to date with 'origin/master'.
>
> Changes not staged for commit:
> (use "git add <file>..." to update what will be committed)
> (use "git restore <file>..." to discard changes in working directory)
> modified: LICENSE
>
> no changes added to commit (use "git add" and/or "git commit -a")
>
> ❯ git checkout 0-1-stable
> error: Your local changes to the following files would be overwritten
> by checkout:
> LICENSE
> Please commit your changes or stash them before you switch branches.
> Aborting
>
> So won't this simply be duplicating the same message?
>
> > statusAheadBehind::
> > Shown when linkgit:git-status[1] computes the ahead/behind
> > counts for a local ref compared to its remote tracking ref,
> > diff --git a/advice.c b/advice.c
> > index 0018501b7b..e1264f525c 100644
> > --- a/advice.c
> > +++ b/advice.c
> > @@ -81,6 +81,7 @@ static struct {
> > [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> > [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> > [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> > + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> > [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> > [ADVICE_STATUS_HINTS] = { "statusHints" },
> > [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> > @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> > "* Use \"git add --sparse <paths>\" to update the index\n"
> > "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> > }
> > +
> > +void advise_on_checkout_dirty_files(struct string_list *file_list)
> > +{
> > + struct string_list_item *item;
> > +
> > + if (!file_list->nr)
> > + return;
> > +
> > + fprintf(stderr, _("The following files have local modifications that would\n"
> > + "be overwritten by switching branches:\n"));
> > + for_each_string_list_item(item, file_list)
> > + fprintf(stderr, "\t%s\n", item->string);
> > +
> > + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
> > + _("You can save your local changes before switching by running:\n"
> > + "\n"
> > + "\tgit stash push\n"
> > + "\n"
> > + "Then restore them after switching with:\n"
> > + "\n"
> > + "\tgit stash pop\n"
> > + "\n"
> > + "Or to discard your local changes, use:\n"
> > + "\n"
> > + "\tgit checkout -- <file>"));
> > +}
>
> This doesn't seem to be formatted with tabs.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 14:37 ` Arsh Srivastava
@ 2026-03-10 14:40 ` Arsh Srivastava
2026-03-10 17:15 ` Karthik Nayak
2026-03-10 14:41 ` Arsh Srivastava
2026-03-10 16:48 ` Junio C Hamano
2 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 14:40 UTC (permalink / raw)
To: Karthik Nayak; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
branch switches
Patrick Steinhardt <ps@pks.im> writes:
> It is used in "add.c", but not magically so. The function that you have
> introduced is the only site that uses the new advice, but the function
> is never called as far as I can see. So ultimately, the proposed change
> does not have any effect on the user-observable behaviour.
Thank you for the correction and for the bottom-posting reminder.
You are right. The function advise_on_checkout_dirty_files() is defined
but never called anywhere, so the patch has no user-observable effect.
I also looked into the existing behaviour more carefully and found that
unpack-trees.c already handles this case and prints a message telling
the user to commit or stash their changes before switching branches.
So the patch as written is both incomplete and duplicates existing
behaviour. I will rework it in v3 to instead enhance the existing
message in unpack-trees.c to also mention 'git checkout -m' for users
who want to carry their local changes over to the new branch.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 20:07, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> branch switches
>
> Karthik Nayak <karthik.188@gmail.com> writes:
>
> > Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> > So won't this simply be duplicating the same message?
>
> Thank you for the detailed review. You are correct, the existing message
> in unpack-trees.c already handles this case and my patch duplicates it.
> I also acknowledge the other issues raised:
>
> - The newly introduced function was never called anywhere in the codebase
> - No tests were added
> - The bullet points in the commit message used '>' instead of '-' or '*'
> - The advice message was not formatted with tabs
>
> Rather than duplicating the existing behaviour, I think the better
> approach would be to enhance the existing message in unpack-trees.c to
> also mention 'git checkout -m' as an option for users who want to carry
> their local changes over to the new branch, since the current message
> only says "commit or stash" without mentioning that option.
>
> I will rework the patch in that direction and send a v4.
>
> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> On Tue, 10 Mar 2026 at 20:01, Karthik Nayak <karthik.188@gmail.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > From: Arsh Srivastava <arshsrivastava00@gmail.com>
> > >
> > > Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
> > > when they attempt to switch branches with local modifications that
> > > would be overwritten by the operation.
> > >
> > > This includes:
> > >> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> > >> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> > >> New advise_on_checkout_dirty_files() function that lists the
> > > affected files and suggests using git stash push/pop
> > >> Documentation entry in Documentation/config/advice.txt
> > >
> >
> > Nit: Did you mean to add bullet point here? '>' is generally used to
> > quote text. Perhaps use '-' or '*'.
> >
> > [snip]
> >
> > >
> > > Documentation/config/advice.adoc | 5 +++++
> > > advice.c | 27 +++++++++++++++++++++++++++
> > > advice.h | 2 ++
> > > 3 files changed, 34 insertions(+)
> > >
> >
> > Hmm. Shouldn't there be changes which actually call the newly introduced
> > function? Also shouldn't there be tests added?
> >
> > > diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
> > > index 257db58918..8752e05636 100644
> > > --- a/Documentation/config/advice.adoc
> > > +++ b/Documentation/config/advice.adoc
> > > @@ -126,6 +126,11 @@ all advice messages.
> > > Shown when a sparse index is expanded to a full index, which is likely
> > > due to an unexpected set of files existing outside of the
> > > sparse-checkout.
> > > + stashBeforeCheckout::
> > > + Shown when the user attempts to switch branches but has
> > > + local modifications that would be overwritten by the
> > > + operation, to suggest using linkgit:git-stash[1] to
> > > + save changes before switching.
> >
> > Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> >
> > In one of my repos:
> >
> > ❯ git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > nothing to commit, working tree clean
> >
> > ❯ echo "aldjf" >> LICENSE
> >
> > ❯ git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > Changes not staged for commit:
> > (use "git add <file>..." to update what will be committed)
> > (use "git restore <file>..." to discard changes in working directory)
> > modified: LICENSE
> >
> > no changes added to commit (use "git add" and/or "git commit -a")
> >
> > ❯ git checkout 0-1-stable
> > error: Your local changes to the following files would be overwritten
> > by checkout:
> > LICENSE
> > Please commit your changes or stash them before you switch branches.
> > Aborting
> >
> > So won't this simply be duplicating the same message?
> >
> > > statusAheadBehind::
> > > Shown when linkgit:git-status[1] computes the ahead/behind
> > > counts for a local ref compared to its remote tracking ref,
> > > diff --git a/advice.c b/advice.c
> > > index 0018501b7b..e1264f525c 100644
> > > --- a/advice.c
> > > +++ b/advice.c
> > > @@ -81,6 +81,7 @@ static struct {
> > > [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> > > [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> > > [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> > > + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> > > [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> > > [ADVICE_STATUS_HINTS] = { "statusHints" },
> > > [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> > > @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> > > "* Use \"git add --sparse <paths>\" to update the index\n"
> > > "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> > > }
> > > +
> > > +void advise_on_checkout_dirty_files(struct string_list *file_list)
> > > +{
> > > + struct string_list_item *item;
> > > +
> > > + if (!file_list->nr)
> > > + return;
> > > +
> > > + fprintf(stderr, _("The following files have local modifications that would\n"
> > > + "be overwritten by switching branches:\n"));
> > > + for_each_string_list_item(item, file_list)
> > > + fprintf(stderr, "\t%s\n", item->string);
> > > +
> > > + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
> > > + _("You can save your local changes before switching by running:\n"
> > > + "\n"
> > > + "\tgit stash push\n"
> > > + "\n"
> > > + "Then restore them after switching with:\n"
> > > + "\n"
> > > + "\tgit stash pop\n"
> > > + "\n"
> > > + "Or to discard your local changes, use:\n"
> > > + "\n"
> > > + "\tgit checkout -- <file>"));
> > > +}
> >
> > This doesn't seem to be formatted with tabs.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 14:37 ` Arsh Srivastava
2026-03-10 14:40 ` Arsh Srivastava
@ 2026-03-10 14:41 ` Arsh Srivastava
2026-03-10 16:48 ` Junio C Hamano
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 14:41 UTC (permalink / raw)
To: Karthik Nayak; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
branch switches
Patrick Steinhardt <ps@pks.im> writes:
> It is used in "add.c", but not magically so. The function that you have
> introduced is the only site that uses the new advice, but the function
> is never called as far as I can see. So ultimately, the proposed change
> does not have any effect on the user-observable behaviour.
Thank you for the correction and for the bottom-posting reminder.
You are right. The function advise_on_checkout_dirty_files() is defined
but never called anywhere, so the patch has no user-observable effect.
I also looked into the existing behaviour more carefully and found that
unpack-trees.c already handles this case and prints a message telling
the user to commit or stash their changes before switching branches.
So the patch as written is both incomplete and duplicates existing
behaviour. I will rework it in v4 to instead enhance the existing
message in unpack-trees.c to also mention 'git checkout -m' for users
who want to carry their local changes over to the new branch.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 20:07, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> branch switches
>
> Karthik Nayak <karthik.188@gmail.com> writes:
>
> > Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> > So won't this simply be duplicating the same message?
>
> Thank you for the detailed review. You are correct, the existing message
> in unpack-trees.c already handles this case and my patch duplicates it.
> I also acknowledge the other issues raised:
>
> - The newly introduced function was never called anywhere in the codebase
> - No tests were added
> - The bullet points in the commit message used '>' instead of '-' or '*'
> - The advice message was not formatted with tabs
>
> Rather than duplicating the existing behaviour, I think the better
> approach would be to enhance the existing message in unpack-trees.c to
> also mention 'git checkout -m' as an option for users who want to carry
> their local changes over to the new branch, since the current message
> only says "commit or stash" without mentioning that option.
>
> I will rework the patch in that direction and send a v4.
>
> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> On Tue, 10 Mar 2026 at 20:01, Karthik Nayak <karthik.188@gmail.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > From: Arsh Srivastava <arshsrivastava00@gmail.com>
> > >
> > > Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
> > > when they attempt to switch branches with local modifications that
> > > would be overwritten by the operation.
> > >
> > > This includes:
> > >> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> > >> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> > >> New advise_on_checkout_dirty_files() function that lists the
> > > affected files and suggests using git stash push/pop
> > >> Documentation entry in Documentation/config/advice.txt
> > >
> >
> > Nit: Did you mean to add bullet point here? '>' is generally used to
> > quote text. Perhaps use '-' or '*'.
> >
> > [snip]
> >
> > >
> > > Documentation/config/advice.adoc | 5 +++++
> > > advice.c | 27 +++++++++++++++++++++++++++
> > > advice.h | 2 ++
> > > 3 files changed, 34 insertions(+)
> > >
> >
> > Hmm. Shouldn't there be changes which actually call the newly introduced
> > function? Also shouldn't there be tests added?
> >
> > > diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
> > > index 257db58918..8752e05636 100644
> > > --- a/Documentation/config/advice.adoc
> > > +++ b/Documentation/config/advice.adoc
> > > @@ -126,6 +126,11 @@ all advice messages.
> > > Shown when a sparse index is expanded to a full index, which is likely
> > > due to an unexpected set of files existing outside of the
> > > sparse-checkout.
> > > + stashBeforeCheckout::
> > > + Shown when the user attempts to switch branches but has
> > > + local modifications that would be overwritten by the
> > > + operation, to suggest using linkgit:git-stash[1] to
> > > + save changes before switching.
> >
> > Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> >
> > In one of my repos:
> >
> > ❯ git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > nothing to commit, working tree clean
> >
> > ❯ echo "aldjf" >> LICENSE
> >
> > ❯ git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > Changes not staged for commit:
> > (use "git add <file>..." to update what will be committed)
> > (use "git restore <file>..." to discard changes in working directory)
> > modified: LICENSE
> >
> > no changes added to commit (use "git add" and/or "git commit -a")
> >
> > ❯ git checkout 0-1-stable
> > error: Your local changes to the following files would be overwritten
> > by checkout:
> > LICENSE
> > Please commit your changes or stash them before you switch branches.
> > Aborting
> >
> > So won't this simply be duplicating the same message?
> >
> > > statusAheadBehind::
> > > Shown when linkgit:git-status[1] computes the ahead/behind
> > > counts for a local ref compared to its remote tracking ref,
> > > diff --git a/advice.c b/advice.c
> > > index 0018501b7b..e1264f525c 100644
> > > --- a/advice.c
> > > +++ b/advice.c
> > > @@ -81,6 +81,7 @@ static struct {
> > > [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
> > > [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
> > > [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
> > > + [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
> > > [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
> > > [ADVICE_STATUS_HINTS] = { "statusHints" },
> > > [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
> > > @@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
> > > "* Use \"git add --sparse <paths>\" to update the index\n"
> > > "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
> > > }
> > > +
> > > +void advise_on_checkout_dirty_files(struct string_list *file_list)
> > > +{
> > > + struct string_list_item *item;
> > > +
> > > + if (!file_list->nr)
> > > + return;
> > > +
> > > + fprintf(stderr, _("The following files have local modifications that would\n"
> > > + "be overwritten by switching branches:\n"));
> > > + for_each_string_list_item(item, file_list)
> > > + fprintf(stderr, "\t%s\n", item->string);
> > > +
> > > + advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
> > > + _("You can save your local changes before switching by running:\n"
> > > + "\n"
> > > + "\tgit stash push\n"
> > > + "\n"
> > > + "Then restore them after switching with:\n"
> > > + "\n"
> > > + "\tgit stash pop\n"
> > > + "\n"
> > > + "Or to discard your local changes, use:\n"
> > > + "\n"
> > > + "\tgit checkout -- <file>"));
> > > +}
> >
> > This doesn't seem to be formatted with tabs.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 13:40 ` Arsh Srivastava
@ 2026-03-10 15:40 ` Junio C Hamano
2026-03-10 16:05 ` Arsh Srivastava
2026-03-10 16:08 ` Arsh Srivastava
0 siblings, 2 replies; 62+ messages in thread
From: Junio C Hamano @ 2026-03-10 15:40 UTC (permalink / raw)
To: Arsh Srivastava; +Cc: Phillip Wood, Arsh Srivastava via GitGitGadget, git
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> As per the recommendation of Phillip Wood <phillip.wood123@gmail.com>
> I have changed my files and added git checkout -m after understanding
> its significance :)
It is a given that you as the author of the patch understand it.
What I meant was that the users who get the recommendation need to
be told about the potential issues.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 15:40 ` Junio C Hamano
@ 2026-03-10 16:05 ` Arsh Srivastava
2026-03-10 16:08 ` Arsh Srivastava
1 sibling, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 16:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Phillip Wood, Arsh Srivastava via GitGitGadget, git
Junio C Hamano <gitster@pobox.com> writes:
> It is understood as author that I understand.
> It is the users who need to understand.
As informed by Karthik Nayak <karthik.188@gmail.com> and Patrick
Steinhardt <ps@pks.im>.
My PR seemed to have redundancy for which I will create a v4 for my PR
removing it and giving it proper description for users to understand.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 21:10, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > As per the recommendation of Phillip Wood <phillip.wood123@gmail.com>
> > I have changed my files and added git checkout -m after understanding
> > its significance :)
>
> It is a given that you as the author of the patch understand it.
> What I meant was that the users who get the recommendation need to
> be told about the potential issues.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH 0/5] Advice on checkout dirty files
2026-03-10 15:40 ` Junio C Hamano
2026-03-10 16:05 ` Arsh Srivastava
@ 2026-03-10 16:08 ` Arsh Srivastava
1 sibling, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 16:08 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Phillip Wood, Arsh Srivastava via GitGitGadget, git
Junio C Hamano <gitster@pobox.com> writes:
> It is understood as author that I understand.
> It is the users who need to understand.
> Potential risks for the user.
As informed by Karthik Nayak <karthik.188@gmail.com> and Patrick
Steinhardt <ps@pks.im>.
My PR seemed to have redundancy for which I will create a v4 for my PR
removing it and giving it proper description for users to understand
the possible risks of using -m.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
On Tue, 10 Mar 2026 at 21:10, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > As per the recommendation of Phillip Wood <phillip.wood123@gmail.com>
> > I have changed my files and added git checkout -m after understanding
> > its significance :)
>
> It is a given that you as the author of the patch understand it.
> What I meant was that the users who get the recommendation need to
> be told about the potential issues.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 14:37 ` Arsh Srivastava
2026-03-10 14:40 ` Arsh Srivastava
2026-03-10 14:41 ` Arsh Srivastava
@ 2026-03-10 16:48 ` Junio C Hamano
2026-03-10 17:09 ` Karthik Nayak
2026-03-10 17:56 ` Arsh Srivastava
2 siblings, 2 replies; 62+ messages in thread
From: Junio C Hamano @ 2026-03-10 16:48 UTC (permalink / raw)
To: Arsh Srivastava
Cc: Karthik Nayak, Arsh Srivastava via GitGitGadget, git,
Phillip Wood
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> branch switches
>
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
>> So won't this simply be duplicating the same message?
>
> Thank you for the detailed review. You are correct, the existing message
> ...
> I will rework the patch in that direction and send a v4.
>
> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
Just a comment by a bystander, but it confuses me quite a lot to see
in-body "Subject:" and "Sign-off" in a message that is *not* a patch
at all. What are you signing off with this signature?
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 16:48 ` Junio C Hamano
@ 2026-03-10 17:09 ` Karthik Nayak
2026-03-14 4:27 ` Konstantin Ryabitsev
2026-03-10 17:56 ` Arsh Srivastava
1 sibling, 1 reply; 62+ messages in thread
From: Karthik Nayak @ 2026-03-10 17:09 UTC (permalink / raw)
To: Junio C Hamano, Arsh Srivastava
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
[-- Attachment #1: Type: text/plain, Size: 846 bytes --]
Junio C Hamano <gitster@pobox.com> writes:
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
>> Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
>> branch switches
>>
>> Karthik Nayak <karthik.188@gmail.com> writes:
>>
>>> Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
>>> So won't this simply be duplicating the same message?
>>
>> Thank you for the detailed review. You are correct, the existing message
>> ...
>> I will rework the patch in that direction and send a v4.
>>
>> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> Just a comment by a bystander, but it confuses me quite a lot to see
> in-body "Subject:" and "Sign-off" in a message that is *not* a patch
> at all. What are you signing off with this signature?
Tangentially, I know that b4 adds a "Sign-off" to the cover message.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 14:40 ` Arsh Srivastava
@ 2026-03-10 17:15 ` Karthik Nayak
2026-03-10 18:00 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Karthik Nayak @ 2026-03-10 17:15 UTC (permalink / raw)
To: Arsh Srivastava; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
[-- Attachment #1: Type: text/plain, Size: 1541 bytes --]
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> branch switches
>
> Patrick Steinhardt <ps@pks.im> writes:
>
>> It is used in "add.c", but not magically so. The function that you have
>> introduced is the only site that uses the new advice, but the function
>> is never called as far as I can see. So ultimately, the proposed change
>> does not have any effect on the user-observable behaviour.
>
> Thank you for the correction and for the bottom-posting reminder.
>
> You are right. The function advise_on_checkout_dirty_files() is defined
> but never called anywhere, so the patch has no user-observable effect.
> I also looked into the existing behaviour more carefully and found that
> unpack-trees.c already handles this case and prints a message telling
> the user to commit or stash their changes before switching branches.
>
> So the patch as written is both incomplete and duplicates existing
> behaviour. I will rework it in v3 to instead enhance the existing
> message in unpack-trees.c to also mention 'git checkout -m' for users
> who want to carry their local changes over to the new branch.
>
I must say that the patch itself and the responses seem like they're
generated with LLMs. Our guidelines for AI usage within the Git project
are laid out in 'Documentation/SubmittingPatches'.
For GSoC specifically, we have laid out our expectations here [1].
Please go through them.
[1]: https://git.github.io/General-Application-Information/
[snip]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 16:48 ` Junio C Hamano
2026-03-10 17:09 ` Karthik Nayak
@ 2026-03-10 17:56 ` Arsh Srivastava
1 sibling, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 17:56 UTC (permalink / raw)
To: Junio C Hamano
Cc: Karthik Nayak, Arsh Srivastava via GitGitGadget, git,
Phillip Wood
Junio C Hamano <gitster@pobox.com> writes
>Sign-off and Subject in body confuses
I thought writing sign-off was a necessity for my mail to be accepted
On Tue, 10 Mar 2026 at 22:18, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> > branch switches
> >
> > Karthik Nayak <karthik.188@gmail.com> writes:
> >
> >> Doesn't 'ADVICE_COMMIT_BEFORE_MERGE' already do this?
> >> So won't this simply be duplicating the same message?
> >
> > Thank you for the detailed review. You are correct, the existing message
> > ...
> > I will rework the patch in that direction and send a v4.
> >
> > Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> Just a comment by a bystander, but it confuses me quite a lot to see
> in-body "Subject:" and "Sign-off" in a message that is *not* a patch
> at all. What are you signing off with this signature?
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 17:15 ` Karthik Nayak
@ 2026-03-10 18:00 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-10 18:00 UTC (permalink / raw)
To: Karthik Nayak; +Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood
Karthik Nayak <karthik.188@gmail.com> writes
> Use of Ai in patches and messages
> Suggest the documentation for the same
After reading the document carefully again , I understood my mistakes
and I promise to not repeat it again while submitting future PR and
commits.
I am deeply sorry for the mistakes I made and promise to never repeat
them again including in submission of version 4 of my current PR
On Tue, 10 Mar 2026 at 22:45, Karthik Nayak <karthik.188@gmail.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Subject: Re: [GSOC] advice: add stashBeforeCheckout advice for dirty
> > branch switches
> >
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> >> It is used in "add.c", but not magically so. The function that you have
> >> introduced is the only site that uses the new advice, but the function
> >> is never called as far as I can see. So ultimately, the proposed change
> >> does not have any effect on the user-observable behaviour.
> >
> > Thank you for the correction and for the bottom-posting reminder.
> >
> > You are right. The function advise_on_checkout_dirty_files() is defined
> > but never called anywhere, so the patch has no user-observable effect.
> > I also looked into the existing behaviour more carefully and found that
> > unpack-trees.c already handles this case and prints a message telling
> > the user to commit or stash their changes before switching branches.
> >
> > So the patch as written is both incomplete and duplicates existing
> > behaviour. I will rework it in v3 to instead enhance the existing
> > message in unpack-trees.c to also mention 'git checkout -m' for users
> > who want to carry their local changes over to the new branch.
> >
>
> I must say that the patch itself and the responses seem like they're
> generated with LLMs. Our guidelines for AI usage within the Git project
> are laid out in 'Documentation/SubmittingPatches'.
>
> For GSoC specifically, we have laid out our expectations here [1].
> Please go through them.
>
> [1]: https://git.github.io/General-Application-Information/
>
> [snip]
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v4 0/5] Advice on checkout dirty files
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (6 more replies)
2 siblings, 7 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
when they attempt to switch branches with local modifications that would be
overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save and
restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> "stashBeforeCheckout" to advice_setting[] and implement
> advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Arsh Srivastava (5):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
Updating tests and unpack-tress.c [GSOC]
File updation [GSOC]
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v3:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
-: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
-: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC]
-: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
--
gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
` (5 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
+ stashBeforeCheckout::
+ Shown when the user attempts to switch branches but has
+ local modifications that would be overwritten by the
+ operation, to suggest using linkgit:git-stash[1] to
+ save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
+ [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
+
+void advise_on_checkout_dirty_files(struct string_list *file_list)
+{
+ struct string_list_item *item;
+
+ if (!file_list->nr)
+ return;
+
+ fprintf(stderr, _("The following files have local modifications that would\n"
+ "be overwritten by switching branches:\n"));
+ for_each_string_list_item(item, file_list)
+ fprintf(stderr, "\t%s\n", item->string);
+
+ advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
+ _("You can save your local changes before switching by running:\n"
+ "\n"
+ "\tgit stash push\n"
+ "\n"
+ "Then restore them after switching with:\n"
+ "\n"
+ "\tgit stash pop\n"
+ "\n"
+ "Or to discard your local changes, use:\n"
+ "\n"
+ "\tgit checkout -- <file>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
+ ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
+void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
` (4 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes
over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement
advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
advice.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/advice.c b/advice.c
index e1264f525c..ba290d3760 100644
--- a/advice.c
+++ b/advice.c
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)
fprintf(stderr, "\t%s\n", item->string);
advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
- _("You can save your local changes before switching by running:\n"
+ _("To carry your local changes over to the new branch, use:\n"
"\n"
- "\tgit stash push\n"
- "\n"
- "Then restore them after switching with:\n"
- "\n"
- "\tgit stash pop\n"
- "\n"
- "Or to discard your local changes, use:\n"
- "\n"
- "\tgit checkout -- <file>"));
+ "\tgit checkout -m <branch>\n"
+ ));
}
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC] Arsh Srivastava via GitGitGadget
` (3 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
This comment is an extention to the already existing stash comment.
After the valuable insights given to me by git maintaniers.
I removed the new function I introduced.
Added updated comment over the already existing function
"setup_unpack_trees_porcelain" with "git checkout -m <branch>"
and its repercussions
I have also mentioned the repercussions of using "-m".
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 -----
advice.c | 20 --------------------
advice.h | 2 --
unpack-trees.c | 13 +++++++++++--
4 files changed, 11 insertions(+), 29 deletions(-)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 8752e05636..257db58918 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,11 +126,6 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
- stashBeforeCheckout::
- Shown when the user attempts to switch branches but has
- local modifications that would be overwritten by the
- operation, to suggest using linkgit:git-stash[1] to
- save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index ba290d3760..0018501b7b 100644
--- a/advice.c
+++ b/advice.c
@@ -81,7 +81,6 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
- [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
-
-void advise_on_checkout_dirty_files(struct string_list *file_list)
-{
- struct string_list_item *item;
-
- if (!file_list->nr)
- return;
-
- fprintf(stderr, _("The following files have local modifications that would\n"
- "be overwritten by switching branches:\n"));
- for_each_string_list_item(item, file_list)
- fprintf(stderr, "\t%s\n", item->string);
-
- advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
- _("To carry your local changes over to the new branch, use:\n"
- "\n"
- "\tgit checkout -m <branch>\n"
- ));
-}
diff --git a/advice.h b/advice.h
index c035b5d8e3..8def280688 100644
--- a/advice.h
+++ b/advice.h
@@ -48,7 +48,6 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
- ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
-void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9449ee8203 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,17 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "Please commit your changes or stash them before you switch branches.\n"
+ "Try using 'git checkout -m <branch>' for a quick fix. \n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.\n"
+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ );
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 5/5] File updation [GSOC] Arsh Srivastava via GitGitGadget
` (2 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
While submitting my previous commit found that
previous testcases weren't working properly
with my updates
So fixed the test updates and advice conflict issue.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
t/t6439-merge-co-error-msgs.sh | 4 ++++
t/t7406-submodule-update.sh | 2 ++
unpack-trees.c | 6 +-----
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..6ebc1d2565 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +101,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..a359429bf5 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,8 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 9449ee8203..cb4cdee9b9 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -134,11 +134,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
)
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.\n"
- "Try using 'git checkout -m <branch>' for a quick fix.\n"
- "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
- "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
- );
+ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v4 5/5] File updation [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (3 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
I have ran tests locally for this file
and tried to fix all the CI issues
Lets Hope it works
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
t/t6439-merge-co-error-msgs.sh | 6 ++++--
t/t7406-submodule-update.sh | 3 ++-
unpack-trees.c | 2 +-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 6ebc1d2565..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -78,7 +78,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/two
Please commit your changes or stash them before you switch branches.
Try using 'git checkout -m <branch>' for a quick fix.
-Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -102,7 +103,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/two
Please commit your changes or stash them before you switch branches.
Try using 'git checkout -m <branch>' for a quick fix.
-Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index a359429bf5..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -213,7 +213,8 @@ test_expect_success 'submodule update should fail due to local changes' '
> file
> Please commit your changes or stash them before you switch branches.
> Try using '\''git checkout -m <branch>'\'' for a quick fix.
- > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index cb4cdee9b9..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -129,7 +129,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.\n"
- "Try using 'git checkout -m <branch>' for a quick fix. \n"
+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
"Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
"Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
)
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH v4 0/5] Advice on checkout dirty files
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (4 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 5/5] File updation [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 16:38 ` Junio C Hamano
2026-03-11 17:06 ` Arsh Srivastava
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
6 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-11 16:38 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> This is my submission for microproject [GSOC]
>
> This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> when they attempt to switch branches with local modifications that would be
> overwritten by the operation.
>
> The new advice follows the same patterns established by existing advice
> functions such as advise_on_updating_sparse_paths(). When triggered, it
> lists the affected files and suggests using git stash push/pop to save and
> restore local changes.
>
> The advice can be silenced with:
>
> git config set advice.stashBeforeCheckout false
>
> Changes:
>
>> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
>> "stashBeforeCheckout" to advice_setting[] and implement
>> advise_on_checkout_dirty_files() function
>> Documentation/config/advice.adoc: document the new advice key
>
> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Even though no developer is perfect, when you are presenting your
updated work, armed with wisdom borrowed from your reviewers'
comments on your earlier attempts, you are expected to take the
opportunity to pretend to have written a series of patches that are
perfect logical progression towards the final shape of the code
without detours, change of plans, and fixing earlier mistakes made
in the series.
Please do not throw a drunken-man's-walk series at us. For example,
I see that [PATCH 3/5] literally removes what was added by earlier
patches. This is not a place for you to show how you made wrong
turns before arriving at the final shape of the code.
The final series accepted by the project will have to stay in our
history for later developers to see in "git log" output to learn
from, and a series being clean logical progression is a must for
that to happen.
Also, what is "updation"? Is it a standard English word, or some
dialect of an LLM origin?
> Arsh Srivastava (5):
> advice: add stashBeforeCheckout advice for dirty branch switches
> advice: add stashBeforeCheckout advice for dirty branch switches
> [GSOC]
> unpack-trees: suggesting 'git checkout -m <branch>' with its
> repercussions
> Updating tests and unpack-tress.c [GSOC]
> File updation [GSOC]
>
> t/t6439-merge-co-error-msgs.sh | 6 ++++++
> t/t7406-submodule-update.sh | 3 +++
> unpack-trees.c | 9 +++++++--
> 3 files changed, 16 insertions(+), 2 deletions(-)
>
>
> base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
> Pull-Request: https://github.com/git/git/pull/2233
>
> Range-diff vs v3:
>
> 1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
> 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
> -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
> -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC]
> -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v4 0/5] Advice on checkout dirty files
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
@ 2026-03-11 17:06 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-11 17:06 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :-
> provide perfect logic not drunken-man's-walk series.
> not a place for you to show how you made wrong turns before arriving at the final shape of the code.
> history for later developers to see in "git log" output to learn from
> what is "updation"
Thank you so much for your feedback.
Again terribly sorry I will rebase my commit so that it has perfect progression.
And updation is a noun first published in Oxford English Dictionary in 2018.
On Wed, 11 Mar 2026 at 22:08, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > This is my submission for microproject [GSOC]
> >
> > This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> > when they attempt to switch branches with local modifications that would be
> > overwritten by the operation.
> >
> > The new advice follows the same patterns established by existing advice
> > functions such as advise_on_updating_sparse_paths(). When triggered, it
> > lists the affected files and suggests using git stash push/pop to save and
> > restore local changes.
> >
> > The advice can be silenced with:
> >
> > git config set advice.stashBeforeCheckout false
> >
> > Changes:
> >
> >> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> >> "stashBeforeCheckout" to advice_setting[] and implement
> >> advise_on_checkout_dirty_files() function
> >> Documentation/config/advice.adoc: document the new advice key
> >
> > Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>
> Even though no developer is perfect, when you are presenting your
> updated work, armed with wisdom borrowed from your reviewers'
> comments on your earlier attempts, you are expected to take the
> opportunity to pretend to have written a series of patches that are
> perfect logical progression towards the final shape of the code
> without detours, change of plans, and fixing earlier mistakes made
> in the series.
>
> Please do not throw a drunken-man's-walk series at us. For example,
> I see that [PATCH 3/5] literally removes what was added by earlier
> patches. This is not a place for you to show how you made wrong
> turns before arriving at the final shape of the code.
>
> The final series accepted by the project will have to stay in our
> history for later developers to see in "git log" output to learn
> from, and a series being clean logical progression is a must for
> that to happen.
>
> Also, what is "updation"? Is it a standard English word, or some
> dialect of an LLM origin?
>
> > Arsh Srivastava (5):
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > [GSOC]
> > unpack-trees: suggesting 'git checkout -m <branch>' with its
> > repercussions
> > Updating tests and unpack-tress.c [GSOC]
> > File updation [GSOC]
> >
> > t/t6439-merge-co-error-msgs.sh | 6 ++++++
> > t/t7406-submodule-update.sh | 3 +++
> > unpack-trees.c | 9 +++++++--
> > 3 files changed, 16 insertions(+), 2 deletions(-)
> >
> >
> > base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
> > Pull-Request: https://github.com/git/git/pull/2233
> >
> > Range-diff vs v3:
> >
> > 1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
> > 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
> > -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
> > -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC]
> > -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v5 0/3] Advice on checkout dirty files
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (5 preceding siblings ...)
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (4 more replies)
6 siblings, 5 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
when they attempt to switch branches with local modifications that would be
overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save and
restore local changes.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> "stashBeforeCheckout" to advice_setting[] and implement
> advise_on_checkout_dirty_files() function
> Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Arsh Srivastava (3):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v5
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v4:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
3: 4237b9667d ! 3: 1cc22f437e unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ advice.h: void NORETURN die_ff_impossible(void);
#endif /* ADVICE_H */
+ ## t/t6439-merge-co-error-msgs.sh ##
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+
+ ## t/t7406-submodule-update.sh ##
+@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ > error: Your local changes to the following files would be overwritten by checkout:
+ > file
+ > Please commit your changes or stash them before you switch branches.
++ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
++ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ > Aborting
+ > fatal: Unable to checkout OID in submodule path '\''submodule'\''
+ EOF
+
## unpack-trees.c ##
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix. \n"
++ "Try using 'git checkout -m <branch>' for a quick fix.\n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
-+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
-+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
-+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
-+ );
++ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
4: b25ea22410 < -: ---------- Updating tests and unpack-tress.c [GSOC]
5: 2ef7d5a3d6 < -: ---------- File updation [GSOC]
--
gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
` (3 subsequent siblings)
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
+ stashBeforeCheckout::
+ Shown when the user attempts to switch branches but has
+ local modifications that would be overwritten by the
+ operation, to suggest using linkgit:git-stash[1] to
+ save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
+ [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -312,3 +313,29 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
+
+void advise_on_checkout_dirty_files(struct string_list *file_list)
+{
+ struct string_list_item *item;
+
+ if (!file_list->nr)
+ return;
+
+ fprintf(stderr, _("The following files have local modifications that would\n"
+ "be overwritten by switching branches:\n"));
+ for_each_string_list_item(item, file_list)
+ fprintf(stderr, "\t%s\n", item->string);
+
+ advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
+ _("You can save your local changes before switching by running:\n"
+ "\n"
+ "\tgit stash push\n"
+ "\n"
+ "Then restore them after switching with:\n"
+ "\n"
+ "\tgit stash pop\n"
+ "\n"
+ "Or to discard your local changes, use:\n"
+ "\n"
+ "\tgit checkout -- <file>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
+ ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -83,5 +84,6 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
+void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
` (2 subsequent siblings)
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.
The advice suggests using "git checkout -m" to carry local changes
over to the new branch in a single step.
The advice can be silenced with:
git config set advice.stashBeforeCheckout false
Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement
advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
advice.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/advice.c b/advice.c
index e1264f525c..ba290d3760 100644
--- a/advice.c
+++ b/advice.c
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)
fprintf(stderr, "\t%s\n", item->string);
advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
- _("You can save your local changes before switching by running:\n"
+ _("To carry your local changes over to the new branch, use:\n"
"\n"
- "\tgit stash push\n"
- "\n"
- "Then restore them after switching with:\n"
- "\n"
- "\tgit stash pop\n"
- "\n"
- "Or to discard your local changes, use:\n"
- "\n"
- "\tgit checkout -- <file>"));
+ "\tgit checkout -m <branch>\n"
+ ));
}
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
This comment is an extention to the already existing stash comment.
After the valuable insights given to me by git maintaniers.
I removed the new function I introduced.
Added updated comment over the already existing function
"setup_unpack_trees_porcelain" with "git checkout -m <branch>"
and its repercussions
I have also mentioned the repercussions of using "-m".
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 -----
advice.c | 20 --------------------
advice.h | 2 --
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
6 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 8752e05636..257db58918 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,11 +126,6 @@ all advice messages.
Shown when a sparse index is expanded to a full index, which is likely
due to an unexpected set of files existing outside of the
sparse-checkout.
- stashBeforeCheckout::
- Shown when the user attempts to switch branches but has
- local modifications that would be overwritten by the
- operation, to suggest using linkgit:git-stash[1] to
- save changes before switching.
statusAheadBehind::
Shown when linkgit:git-status[1] computes the ahead/behind
counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index ba290d3760..0018501b7b 100644
--- a/advice.c
+++ b/advice.c
@@ -81,7 +81,6 @@ static struct {
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
- [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
[ADVICE_STATUS_HINTS] = { "statusHints" },
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
"* Use \"git add --sparse <paths>\" to update the index\n"
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
}
-
-void advise_on_checkout_dirty_files(struct string_list *file_list)
-{
- struct string_list_item *item;
-
- if (!file_list->nr)
- return;
-
- fprintf(stderr, _("The following files have local modifications that would\n"
- "be overwritten by switching branches:\n"));
- for_each_string_list_item(item, file_list)
- fprintf(stderr, "\t%s\n", item->string);
-
- advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
- _("To carry your local changes over to the new branch, use:\n"
- "\n"
- "\tgit checkout -m <branch>\n"
- ));
-}
diff --git a/advice.h b/advice.h
index c035b5d8e3..8def280688 100644
--- a/advice.h
+++ b/advice.h
@@ -48,7 +48,6 @@ enum advice_type {
ADVICE_SET_UPSTREAM_FAILURE,
ADVICE_SKIPPED_CHERRY_PICKS,
ADVICE_SPARSE_INDEX_EXPANDED,
- ADVICE_STASH_BEFORE_CHECKOUT,
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
ADVICE_STATUS_HINTS,
ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
void advise_on_moving_dirty_path(struct string_list *pathspec_list);
-void advise_on_checkout_dirty_files(struct string_list *file_list);
#endif /* ADVICE_H */
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "Please commit your changes or stash them before you switch branches.\n"
+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH v5 0/3] Advice on checkout dirty files
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-11 17:49 ` [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-12 1:02 ` Junio C Hamano
2026-03-12 3:32 ` Arsh Srivastava
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
4 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 1:02 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> Changes:
>
>> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
>> "stashBeforeCheckout" to advice_setting[] and implement
>> advise_on_checkout_dirty_files() function
>> Documentation/config/advice.adoc: document the new advice key
>
> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>
> Arsh Srivastava (3):
> advice: add stashBeforeCheckout advice for dirty branch switches
> advice: add stashBeforeCheckout advice for dirty branch switches
> [GSOC]
> unpack-trees: suggesting 'git checkout -m <branch>' with its
> repercussions
I still see that [PATCH 3/3] literally removes what was added by
earlier patches. ADVICE_STASH_BEFORE_CHECKOUT is added to
advice.[ch] and stashBeforeCheckOut is added to
Documentation/config/adivce.adoc in [1/3], and then they are removed
in [3/3]. If your final solution does not involve such an advice,
then do not even add it in an earlier patch, only to retract it and
replace it with something else in a later patch. If the reason why
that "something else" replaces the advice is because it is a better
solution to the problem you initially started to solve than the
advice message added in [1/3], then just go straight to that
"something else", without adding and removing the advice mechanism.
That is what "perfect logical progression without detours, change of
plans, and fixes earlier mistake" is about.
In other words, please do not throw a drunken-man's-walk series at
us. Pretend to be a perfect developer.
The final series accepted by the project will have to stay in our
history for later developers to see in "git log" output to learn
from, and a series being clean logical progression is a must for
that to happen.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v5 0/3] Advice on checkout dirty files
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
@ 2026-03-12 3:32 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 3:32 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> He still see 3 patches for a work that can be done by one.
> That is what "perfect logical progression without detours, change of
> plans, and fixes earlier mistake" is about.
> please do not throw a drunken-man's-walk series at
> us. Pretend to be a perfect developer
I understand now sorry for the inconvenience.
Your mail also specified the same thing but I was not able to truly
grasp the essence of that mail.
Thank you for explaining it again to me, I now have clear
understanding of what is expected from me.
I will create one single commit :) .
I also saw that git via git gadget forwards all my commits making it
messy and not ideal.
I will make a clean single commit that will look perfect and wouldn't
make such a messy commit history.
On Thu, 12 Mar 2026 at 06:32, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > Changes:
> >
> >> advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value advice.c: add
> >> "stashBeforeCheckout" to advice_setting[] and implement
> >> advise_on_checkout_dirty_files() function
> >> Documentation/config/advice.adoc: document the new advice key
> >
> > Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
> >
> > Arsh Srivastava (3):
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > [GSOC]
> > unpack-trees: suggesting 'git checkout -m <branch>' with its
> > repercussions
>
> I still see that [PATCH 3/3] literally removes what was added by
> earlier patches. ADVICE_STASH_BEFORE_CHECKOUT is added to
> advice.[ch] and stashBeforeCheckOut is added to
> Documentation/config/adivce.adoc in [1/3], and then they are removed
> in [3/3]. If your final solution does not involve such an advice,
> then do not even add it in an earlier patch, only to retract it and
> replace it with something else in a later patch. If the reason why
> that "something else" replaces the advice is because it is a better
> solution to the problem you initially started to solve than the
> advice message added in [1/3], then just go straight to that
> "something else", without adding and removing the advice mechanism.
>
> That is what "perfect logical progression without detours, change of
> plans, and fixes earlier mistake" is about.
>
> In other words, please do not throw a drunken-man's-walk series at
> us. Pretend to be a perfect developer.
>
> The final series accepted by the project will have to stay in our
> history for later developers to see in "git log" output to learn
> from, and a series being clean logical progression is a must for
> that to happen.
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
` (3 preceding siblings ...)
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
@ 2026-03-12 4:00 ` Arsh Srivastava via GitGitGadget
2026-03-12 16:06 ` Junio C Hamano
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
4 siblings, 2 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-12 4:00 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
This comment is an extention to the already existing stash comment.
Added updated comment over the already existing function
"setup_unpack_trees_porcelain" with "git checkout -m"
and its repercussions
I have also mentioned the repercussions of using "-m".
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand
risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge
configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and
> checkout tests. t/t7406-submodule-update.sh: update expected output
> for submodule checkout tests.
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v6
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v5:
1: eb5639dbc3 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches
2: e88c851701 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
3: 1cc22f437e ! 1: e0ba5fad82 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ Metadata
Author: Arsh Srivastava <arshsrivastava00@gmail.com>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
+ unpack-trees: suggesting 'git checkout -m' with its repercussions
This comment is an extention to the already existing stash comment.
-
- After the valuable insights given to me by git maintaniers.
- I removed the new function I introduced.
Added updated comment over the already existing function
- "setup_unpack_trees_porcelain" with "git checkout -m <branch>"
+ "setup_unpack_trees_porcelain" with "git checkout -m"
and its repercussions
I have also mentioned the repercussions of using "-m".
- Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
-
- ## Documentation/config/advice.adoc ##
-@@ Documentation/config/advice.adoc: all advice messages.
- Shown when a sparse index is expanded to a full index, which is likely
- due to an unexpected set of files existing outside of the
- sparse-checkout.
-- stashBeforeCheckout::
-- Shown when the user attempts to switch branches but has
-- local modifications that would be overwritten by the
-- operation, to suggest using linkgit:git-stash[1] to
-- save changes before switching.
- statusAheadBehind::
- Shown when linkgit:git-status[1] computes the ahead/behind
- counts for a local ref compared to its remote tracking ref,
-
- ## advice.c ##
-@@ advice.c: static struct {
- [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
- [ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
- [ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
-- [ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
- [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
- [ADVICE_STATUS_HINTS] = { "statusHints" },
- [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
-@@ advice.c: void advise_on_moving_dirty_path(struct string_list *pathspec_list)
- "* Use \"git add --sparse <paths>\" to update the index\n"
- "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
- }
--
--void advise_on_checkout_dirty_files(struct string_list *file_list)
--{
-- struct string_list_item *item;
--
-- if (!file_list->nr)
-- return;
--
-- fprintf(stderr, _("The following files have local modifications that would\n"
-- "be overwritten by switching branches:\n"));
-- for_each_string_list_item(item, file_list)
-- fprintf(stderr, "\t%s\n", item->string);
--
-- advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
-- _("To carry your local changes over to the new branch, use:\n"
-- "\n"
-- "\tgit checkout -m <branch>\n"
-- ));
--}
-
- ## advice.h ##
-@@ advice.h: enum advice_type {
- ADVICE_SET_UPSTREAM_FAILURE,
- ADVICE_SKIPPED_CHERRY_PICKS,
- ADVICE_SPARSE_INDEX_EXPANDED,
-- ADVICE_STASH_BEFORE_CHECKOUT,
- ADVICE_STATUS_AHEAD_BEHIND_WARNING,
- ADVICE_STATUS_HINTS,
- ADVICE_STATUS_U_OPTION,
-@@ advice.h: void NORETURN die_ff_impossible(void);
- void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
- void detach_advice(const char *new_name);
- void advise_on_moving_dirty_path(struct string_list *pathspec_list);
--void advise_on_checkout_dirty_files(struct string_list *file_list);
-
- #endif /* ADVICE_H */
+ Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
## t/t6439-merge-co-error-msgs.sh ##
@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,13 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "Please commit your changes or stash them before you switch branches.\n"
+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-12 16:06 ` Junio C Hamano
2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
1 sibling, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 16:06 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> This comment is an extention to the already existing stash comment.
> Added updated comment over the already existing function
> "setup_unpack_trees_porcelain" with "git checkout -m"
> and its repercussions
> I have also mentioned the repercussions of using "-m".
>
> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
The commit message should focus on the "why" and "what" from a user
perspective, following the project's standard format (problem
description, then solution).
Consider a more standard phrasing:
unpack-trees: suggest 'git checkout -m' when checkout fails
When a branch switch fails due to local changes, we suggest
stashing or committing. However, 'git checkout -m' is a valid
alternative for users who wish to carry their changes over via a
merge.
Update the advice message to suggest this option, while
including a warning about the potential for data loss if a hard
reset is performed after a conflicted merge.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m"
in this situation after all.
The added message is quite long:
> Try using 'git checkout -m <branch>' for a quick fix.
> Please Note :- that using -m (merge) will not save your changes,
> rather would directly merge them.
> Meaning if you are not able to resolve conflicts and does --hard
> reset your local changes would be gone.
When advice requires a multi-line warning about potential data loss,
it's often a sign that the operation being suggested isn't suitable
for general advice. The goal of these messages should be to provide
a clear, safe next step, not a list of advanced alternatives with
caveats. After all, the users who need such an "it failed, now what
should I do to recover?" message the most are relatively
inexperienced users and we do not want the advice to be
overwhelming.
The primary concern is that 'git checkout -m' is a high-stakes
operation compared to 'git stash'.
- When a user uses 'git stash', their changes are recorded in a
stash entry. If 'git stash pop' later results in conflicts they
cannot resolve, the user can always 'git reset --hard' to get back
to a clean state, knowing their original changes are still safe in
the stash entry, which they can re-attempt to use later.
- In contrast, 'git checkout -m' performs the merge directly in
the working tree. If conflicts arise, the original local changes
are immediately replaced by conflict markers. Unlike stash, there
is no "undo" record. If the user realizes they are in over their
head, they cannot simply "abort" to get their original changes
back. They have only one chance to resolve it correctly, and they
have to do so right there.
Suggesting this "one-shot" approach to a user who is already in a
state of friction (and likely less experienced) might be providing
them with a "foot-gun" rather than a helpful tip. Generally, advice
that nudges users toward the safest "golden paths" like stashing or
committing is preferred.
For a microproject, you've successfully demonstrated that you can
modify the advice system and update the test suite. However, for the
health of the project's usability, it might be better to drop the
'checkout -m' suggestion and instead focus on making the existing
'stash' and 'commit' advice as clear and helpful as possible.
Thanks.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 16:06 ` Junio C Hamano
@ 2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 18:56 ` Junio C Hamano
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 18:13 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
> Also showed an example for the same.
> Also, note that "extention" is a typo; it should be "extension".
> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
> Pointed out the difference between "stash" and "checkout -m".
> When advice requires a multi-line warning about potential data loss.
> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
Thank you so much for the valuable feedback.
I will redefine my advice and will make it more precise and will
change it to git stash which is truly more beneficial for the new
users.
Also will update my commit so that it is properly structured with
format first "why" then "what".
I will create a v7 with all these changes.
I am really obliged.
Thanks again for the guidance.
On Thu, 12 Mar 2026 at 21:36, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Arsh Srivastava <arshsrivastava00@gmail.com>
> >
> > This comment is an extention to the already existing stash comment.
> > Added updated comment over the already existing function
> > "setup_unpack_trees_porcelain" with "git checkout -m"
> > and its repercussions
> > I have also mentioned the repercussions of using "-m".
> >
> > Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>
> The commit message should focus on the "why" and "what" from a user
> perspective, following the project's standard format (problem
> description, then solution).
>
> Consider a more standard phrasing:
>
> unpack-trees: suggest 'git checkout -m' when checkout fails
>
> When a branch switch fails due to local changes, we suggest
> stashing or committing. However, 'git checkout -m' is a valid
> alternative for users who wish to carry their changes over via a
> merge.
>
> Update the advice message to suggest this option, while
> including a warning about the potential for data loss if a hard
> reset is performed after a conflicted merge.
>
> Also, note that "extention" is a typo; it should be "extension".
>
> Having said that, I am not sure if we want to suggest "checkout -m"
> in this situation after all.
>
> The added message is quite long:
>
> > Try using 'git checkout -m <branch>' for a quick fix.
> > Please Note :- that using -m (merge) will not save your changes,
> > rather would directly merge them.
> > Meaning if you are not able to resolve conflicts and does --hard
> > reset your local changes would be gone.
>
> When advice requires a multi-line warning about potential data loss,
> it's often a sign that the operation being suggested isn't suitable
> for general advice. The goal of these messages should be to provide
> a clear, safe next step, not a list of advanced alternatives with
> caveats. After all, the users who need such an "it failed, now what
> should I do to recover?" message the most are relatively
> inexperienced users and we do not want the advice to be
> overwhelming.
>
> The primary concern is that 'git checkout -m' is a high-stakes
> operation compared to 'git stash'.
>
> - When a user uses 'git stash', their changes are recorded in a
> stash entry. If 'git stash pop' later results in conflicts they
> cannot resolve, the user can always 'git reset --hard' to get back
> to a clean state, knowing their original changes are still safe in
> the stash entry, which they can re-attempt to use later.
>
> - In contrast, 'git checkout -m' performs the merge directly in
> the working tree. If conflicts arise, the original local changes
> are immediately replaced by conflict markers. Unlike stash, there
> is no "undo" record. If the user realizes they are in over their
> head, they cannot simply "abort" to get their original changes
> back. They have only one chance to resolve it correctly, and they
> have to do so right there.
>
> Suggesting this "one-shot" approach to a user who is already in a
> state of friction (and likely less experienced) might be providing
> them with a "foot-gun" rather than a helpful tip. Generally, advice
> that nudges users toward the safest "golden paths" like stashing or
> committing is preferred.
>
> For a microproject, you've successfully demonstrated that you can
> modify the advice system and update the test suite. However, for the
> health of the project's usability, it might be better to drop the
> 'checkout -m' suggestion and instead focus on making the existing
> 'stash' and 'commit' advice as clear and helpful as possible.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 18:13 ` Arsh Srivastava
@ 2026-03-12 18:56 ` Junio C Hamano
2026-03-12 19:03 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 18:56 UTC (permalink / raw)
To: Arsh Srivastava
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> writes :
>> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
>> Also showed an example for the same.
>> Also, note that "extention" is a typo; it should be "extension".
>> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
>> Pointed out the difference between "stash" and "checkout -m".
>> When advice requires a multi-line warning about potential data loss.
>> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
>> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
>> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
>> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
>> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
I wonder where this came from, as it is quite unusual to have a
rephrased summary of what you respond to. Is this LLM-generated
summary that was copied-and-pasted without much human brain effort?
What is more usual is to quote the message you are responding to,
trim the parts you are not going to comment on and not necessary for
bystanders to read in order to understand your response, and then
sprinkle your comments in between the parts of the quoted message,
instead of saying only your thing before the message you are
responding to without trimming (which is highly frowned upon, and
people often tell you not to "top-post").
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 18:56 ` Junio C Hamano
@ 2026-03-12 19:03 ` Arsh Srivastava
2026-03-12 19:07 ` Junio C Hamano
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 19:03 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> write:
> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
> What is more usual is to quote the message you are responding to.
Actually as suspicious as it looks the mail was written by me only and
I thought that each line was as important as other and
I wanted to reply to each point you mentioned
Sorry for shortening your response
next time I will make sure that I will make quotations direct.
On Fri, 13 Mar 2026 at 00:26, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> writes :
> >> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
> >> Also showed an example for the same.
> >> Also, note that "extention" is a typo; it should be "extension".
> >> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
> >> Pointed out the difference between "stash" and "checkout -m".
> >> When advice requires a multi-line warning about potential data loss.
> >> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
> >> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
> >> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
> >> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
> >> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
>
> I wonder where this came from, as it is quite unusual to have a
> rephrased summary of what you respond to. Is this LLM-generated
> summary that was copied-and-pasted without much human brain effort?
>
> What is more usual is to quote the message you are responding to,
> trim the parts you are not going to comment on and not necessary for
> bystanders to read in order to understand your response, and then
> sprinkle your comments in between the parts of the quoted message,
> instead of saying only your thing before the message you are
> responding to without trimming (which is highly frowned upon, and
> people often tell you not to "top-post").
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 19:03 ` Arsh Srivastava
@ 2026-03-12 19:07 ` Junio C Hamano
2026-03-12 19:12 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 19:07 UTC (permalink / raw)
To: Arsh Srivastava
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> write:
>> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
>> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
>> What is more usual is to quote the message you are responding to.
>
> Actually as suspicious as it looks the mail was written by me only and
> I thought that each line was as important as other and
> I wanted to reply to each point you mentioned
> Sorry for shortening your response
> next time I will make sure that I will make quotations direct.
That wasn't what I meant, and you are still top-posting X-<.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 19:07 ` Junio C Hamano
@ 2026-03-12 19:12 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 19:12 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> write:
> That wasn't what I meant, and you are still top-posting X-<.
Oh.. I understand now I mistakenly again used top-posting mail (-<
which is frustrating
I will use the recommended method only from now on. : )
On Fri, 13 Mar 2026 at 00:37, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> write:
> >> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
> >> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
> >> What is more usual is to quote the message you are responding to.
> >
> > Actually as suspicious as it looks the mail was written by me only and
> > I thought that each line was as important as other and
> > I wanted to reply to each point you mentioned
> > Sorry for shortening your response
> > next time I will make sure that I will make quotations direct.
>
> That wasn't what I meant, and you are still top-posting X-<.
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
2026-03-12 16:06 ` Junio C Hamano
@ 2026-03-12 20:05 ` Arsh Srivastava via GitGitGadget
2026-03-12 22:40 ` Junio C Hamano
1 sibling, 1 reply; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-12 20:05 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
When a branch switch fails due to local changes and
new users who are not familiar with the error message often
get confused about how to move ahead and resolve the issue as
the previous error message only suggests to commit or stash the changes
but doesn't explain how to do that or what the next steps are.
This patch enhances the error message with more specific
instructions in a concise manner to help users understand
how to resolve the issue and move their local changes
safely to the other branch using stash.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand
risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge
configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and
> checkout tests. t/t7406-submodule-update.sh: update expected output
> for submodule checkout tests.
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v7
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v6:
1: e0ba5fad82 ! 1: 72cb550621 unpack-trees: suggesting 'git checkout -m' with its repercussions
@@ Metadata
Author: Arsh Srivastava <arshsrivastava00@gmail.com>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m' with its repercussions
+ unpack-trees: suggest using 'git stash' when checkout fails
- This comment is an extention to the already existing stash comment.
- Added updated comment over the already existing function
- "setup_unpack_trees_porcelain" with "git checkout -m"
- and its repercussions
- I have also mentioned the repercussions of using "-m".
+ When a branch switch fails due to local changes and
+ new users who are not familiar with the error message often
+ get confused about how to move ahead and resolve the issue as
+ the previous error message only suggests to commit or stash the changes
+ but doesn't explain how to do that or what the next steps are.
- Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
+ This patch enhances the error message with more specific
+ instructions in a concise manner to help users understand
+ how to resolve the issue and move their local changes
+ safely to the other branch using stash.
+
+ Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
## t/t6439-merge-co-error-msgs.sh ##
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
## t/t7406-submodule-update.sh ##
@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
> file
- > Please commit your changes or stash them before you switch branches.
-+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
-+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+- > Please commit your changes or stash them before you switch branches.
++ > To move you local changes safely to the other branch,
++ > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
-+ "Please commit your changes or stash them before you switch branches.\n"
-+ "Try using 'git checkout -m <branch>' for a quick fix.\n"
-+ "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
-+ "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
++ "To move you local changes safely to the other branch,\n"
++ "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.");
t/t6439-merge-co-error-msgs.sh | 6 ++++--
t/t7406-submodule-update.sh | 3 ++-
unpack-trees.c | 7 +++++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..6ccc1e0416 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -76,7 +76,8 @@ cat >expect <<\EOF
error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
-Please commit your changes or stash them before you switch branches.
+To move you local changes safely to the other branch,
+Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
@@ -98,7 +99,8 @@ cat >expect <<\EOF
error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
-Please commit your changes or stash them before you switch branches.
+To move you local changes safely to the other branch,
+Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..1ba15918a5 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -211,7 +211,8 @@ test_expect_success 'submodule update should fail due to local changes' '
sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
> file
- > Please commit your changes or stash them before you switch branches.
+ > To move you local changes safely to the other branch,
+ > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..e817477926 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,11 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
- "Please commit your changes or stash them before you switch branches.")
- : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+ "To move you local changes safely to the other branch,\n"
+ "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
+ )
+ : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+ "Please commit your changes or stash them before you switch branches.");
else if (!strcmp(cmd, "merge"))
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
@ 2026-03-12 22:40 ` Junio C Hamano
2026-03-13 3:13 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 22:40 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> When a branch switch fails due to local changes and
> new users who are not familiar with the error message often
> get confused about how to move ahead and resolve the issue as
> the previous error message only suggests to commit or stash the changes
> but doesn't explain how to do that or what the next steps are.
The first paragraph is a bit of a run-on and has a misplaced "and";
I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who
are unfamiliar with the error message often get confused about how
to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk
about the current code in the present tense, to highlight what the
problem in the current code is. The _current_ message stops at
hinting the commands to be used without giving wordy instructions
that are best left to manuals. You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so
sure that adding words to the existing message would necessarily
make it more clear.
> This patch enhances the error message with more specific
> instructions in a concise manner to help users understand
> how to resolve the issue and move their local changes
> safely to the other branch using stash.
As Documentation/SubmittingPatches says, let's instruct the code to
"be like so" in imperative mood. E.g., "Enhance the error
message..." instead of "This patch enhances...".
By the way, the updated message seems much less concise than the
original.
> msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> - "Please commit your changes or stash them before you switch branches.")
> - : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> + "To move you local changes safely to the other branch,\n"
> + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> + )
> + : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> + "Please commit your changes or stash them before you switch branches.");
These were already overly long, but the updated one is way too long
to be read on end-user's terminal. The source lines are overly
long, too.
The original was this:
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.")
: _("Your local changes to the following files would be overwritten by checkout:\n%%s");
Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");
without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
)
: _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"Please commit your changes or stash them before you switch branches.");
to those users who decline the advice, we now show "Please
commit...". That is not what !advice_enabled() should trigger, is
it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the
work in progress on the original branch before switching, yet the
new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a
"checkout" might be slightly confusing, even if 'stash pop' involves
a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry
your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike
the right balance between being clear and being concise.
Thanks.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 22:40 ` Junio C Hamano
@ 2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
` (2 more replies)
0 siblings, 3 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 3:13 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> The first paragraph is a bit of a run-on and has a misplaced "and";
> I cannot quite read and understand this overly long single sentence.
> Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible.
With less punctuations and shorter sentences which will in turn make it more
concise.
> Also it is misleading to say "previous" error message. We talk
> about the current code in the present tense, to highlight what the
> problem in the current code is.
Understood I will in future not use previous because it is the
_current_ code.
> You may view it as a weakness (which
> may motivate this patch to be written). But I personally am not so
> sure that adding words to the existing message would necessarily
> make it more clear.
I understand, git wants people to not explore the available
change options and help them make logical decisions rather
than pushing them with some unneeded commands.
> As Documentation/SubmittingPatches says, let's instruct the code to
> "be like so" in imperative mood. E.g., "Enhance the error
> message..." instead of "This patch enhances...".
Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.
> These were already overly long, but the updated one is way too long
> to be read on end-user's terminal. The source lines are overly
> long, too.
That makes total sense.
> to those users who decline the advice, we now show "Please
> commit...". That is not what !advice_enabled() should trigger, is
> it?
Thank you so much for your guidance the advice should not
trigger to those who have opted not to see.
My code might have misjudged this paradigm.
> Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't.
I will remember to be more cautious next time.
> Also the advice lost the other possiblity of first committing the
> work in progress on the original branch before switching, yet the
> new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision
for exploring.
> Also, using "for safe merge" when the user is performing a
> "checkout" might be slightly confusing, even if 'stash pop' involves
> a merge under the hood.
I don't want to sound like a programmed robot but I absolutely
agree with the recommendations.
> But as I already said, I think the current text may already strike
> the right balance between being clear and being concise.
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below,
As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC
perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged?
Because I have already shown I can navigate git project which
was the goal of micro projects in the first place.
On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > When a branch switch fails due to local changes and
> > new users who are not familiar with the error message often
> > get confused about how to move ahead and resolve the issue as
> > the previous error message only suggests to commit or stash the changes
> > but doesn't explain how to do that or what the next steps are.
>
> The first paragraph is a bit of a run-on and has a misplaced "and";
> I cannot quite read and understand this overly long single sentence.
>
> Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> When a branch switch fails due to local changes, new users who
> are unfamiliar with the error message often get confused about how
> to move ahead and resolve the issue.
>
> Also it is misleading to say "previous" error message. We talk
> about the current code in the present tense, to highlight what the
> problem in the current code is. The _current_ message stops at
> hinting the commands to be used without giving wordy instructions
> that are best left to manuals. You may view it as a weakness (which
> may motivate this patch to be written). But I personally am not so
> sure that adding words to the existing message would necessarily
> make it more clear.
>
> > This patch enhances the error message with more specific
> > instructions in a concise manner to help users understand
> > how to resolve the issue and move their local changes
> > safely to the other branch using stash.
>
> As Documentation/SubmittingPatches says, let's instruct the code to
> "be like so" in imperative mood. E.g., "Enhance the error
> message..." instead of "This patch enhances...".
>
> By the way, the updated message seems much less concise than the
> original.
>
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > - "Please commit your changes or stash them before you switch branches.")
> > - : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> > + "To move you local changes safely to the other branch,\n"
> > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> > + )
> > + : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > + "Please commit your changes or stash them before you switch branches.");
>
> These were already overly long, but the updated one is way too long
> to be read on end-user's terminal. The source lines are overly
> long, too.
>
> The original was this:
>
> msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> "Please commit your changes or stash them before you switch branches.")
> : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
>
> Note that when advice is *NOT* enabled, we only gave
>
> _("Your local changes to the following files would be overwritten by checkout:\n%%s");
>
> without any "advise" in the output. That is what !advice_enabled() means.
>
> The updated code does this:
>
> msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> "To move you local changes safely to the other branch,\n"
> "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> )
> : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> "Please commit your changes or stash them before you switch branches.");
>
> to those users who decline the advice, we now show "Please
> commit...". That is not what !advice_enabled() should trigger, is
> it?
>
> Also "To move you" -> "To move your".
>
> Also the advice lost the other possiblity of first committing the
> work in progress on the original branch before switching, yet the
> new advice message is quite wordy.
>
> Also, using "for safe merge" when the user is performing a
> "checkout" might be slightly confusing, even if 'stash pop' involves
> a merge under the hood.
>
> A more concise version might say:
>
> Try 'git stash && git checkout <branch> && git stash pop' to carry
> your changes to the new branch, or commit your work before switching.
>
> But as I already said, I think the current text may already strike
> the right balance between being clear and being concise.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
@ 2026-03-13 10:43 ` Karthik Nayak
2026-03-13 11:02 ` Arsh Srivastava
2026-03-13 22:05 ` Junio C Hamano
2026-03-13 10:49 ` Arsh Srivastava
2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 2 replies; 62+ messages in thread
From: Karthik Nayak @ 2026-03-13 10:43 UTC (permalink / raw)
To: Arsh Srivastava, Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt
[-- Attachment #1: Type: text/plain, Size: 3902 bytes --]
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> writes :
>
>> The first paragraph is a bit of a run-on and has a misplaced "and";
>> I cannot quite read and understand this overly long single sentence.
>> Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
>> Also it is misleading to say "previous" error message. We talk
>> about the current code in the present tense, to highlight what the
>> problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
>> You may view it as a weakness (which
>> may motivate this patch to be written). But I personally am not so
>> sure that adding words to the existing message would necessarily
>> make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
>> As Documentation/SubmittingPatches says, let's instruct the code to
>> "be like so" in imperative mood. E.g., "Enhance the error
>> message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
>> These were already overly long, but the updated one is way too long
>> to be read on end-user's terminal. The source lines are overly
>> long, too.
>
> That makes total sense.
>
>> to those users who decline the advice, we now show "Please
>> commit...". That is not what !advice_enabled() should trigger, is
>> it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
>> Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
>> Also the advice lost the other possiblity of first committing the
>> work in progress on the original branch before switching, yet the
>> new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
>> Also, using "for safe merge" when the user is performing a
>> "checkout" might be slightly confusing, even if 'stash pop' involves
>> a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
>> But as I already said, I think the current text may already strike
>> the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
From the micro-project information [1] for GSoC we have:
The coding part of the microproject should be very small (say, 10-30
minutes). We don’t require that your patch be accepted into the
“master” branch by the time of your formal application; we mostly want
to see that you have a basic level of competence and especially the
ability to interact with the other Git developers.
As such and seeing Junio's previous response, I would say that no
further work is required here.
[1]: https://git.github.io/General-Microproject-Information/
[snip]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
@ 2026-03-13 10:49 ` Arsh Srivastava
2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 10:49 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
Actually the above text should be :-
I understand, git wants people to explore the available
change options and help them make logical decisions rather
than pushing them with some unneeded commands.
On Fri, 13 Mar 2026 at 08:43, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes :
>
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> > Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
> > You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
>
> That makes total sense.
>
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
> > Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
> On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > When a branch switch fails due to local changes and
> > > new users who are not familiar with the error message often
> > > get confused about how to move ahead and resolve the issue as
> > > the previous error message only suggests to commit or stash the changes
> > > but doesn't explain how to do that or what the next steps are.
> >
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> >
> > Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > When a branch switch fails due to local changes, new users who
> > are unfamiliar with the error message often get confused about how
> > to move ahead and resolve the issue.
> >
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is. The _current_ message stops at
> > hinting the commands to be used without giving wordy instructions
> > that are best left to manuals. You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
> >
> > > This patch enhances the error message with more specific
> > > instructions in a concise manner to help users understand
> > > how to resolve the issue and move their local changes
> > > safely to the other branch using stash.
> >
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
> >
> > By the way, the updated message seems much less concise than the
> > original.
> >
> > > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > > - "Please commit your changes or stash them before you switch branches.")
> > > - : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> > > + "To move you local changes safely to the other branch,\n"
> > > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> > > + )
> > > + : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > > + "Please commit your changes or stash them before you switch branches.");
> >
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
> >
> > The original was this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "Please commit your changes or stash them before you switch branches.")
> > : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > Note that when advice is *NOT* enabled, we only gave
> >
> > _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > without any "advise" in the output. That is what !advice_enabled() means.
> >
> > The updated code does this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "To move you local changes safely to the other branch,\n"
> > "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> > )
> > : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "Please commit your changes or stash them before you switch branches.");
> >
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
> >
> > Also "To move you" -> "To move your".
> >
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
> >
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
> >
> > A more concise version might say:
> >
> > Try 'git stash && git checkout <branch> && git stash pop' to carry
> > your changes to the new branch, or commit your work before switching.
> >
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
> >
> > Thanks.
> >
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 10:43 ` Karthik Nayak
@ 2026-03-13 11:02 ` Arsh Srivastava
2026-03-13 22:05 ` Junio C Hamano
1 sibling, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 11:02 UTC (permalink / raw)
To: Karthik Nayak
Cc: Junio C Hamano, Arsh Srivastava via GitGitGadget, git,
Phillip Wood, Patrick Steinhardt
Karthik Nayak <karthik.188@gmail.com> writes :
> We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application
Understandable
> we mostly want to see that you have a basic level of
> competence and especially the
> ability to interact with the other Git developers.
Truly this is something that is very important in any
organization.
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
Thank you so much for your valuable guidance, I will now
draft a formal proposal for GSoC and I look forward to working
with you in the future too. :)
On Fri, 13 Mar 2026 at 16:13, Karthik Nayak <karthik.188@gmail.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> writes :
> >
> >> The first paragraph is a bit of a run-on and has a misplaced "and";
> >> I cannot quite read and understand this overly long single sentence.
> >> Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > In my future commits I will remember to make it as easy to read as possible.
> > With less punctuations and shorter sentences which will in turn make it more
> > concise.
> >
> >> Also it is misleading to say "previous" error message. We talk
> >> about the current code in the present tense, to highlight what the
> >> problem in the current code is.
> >
> > Understood I will in future not use previous because it is the
> > _current_ code.
> >
> >> You may view it as a weakness (which
> >> may motivate this patch to be written). But I personally am not so
> >> sure that adding words to the existing message would necessarily
> >> make it more clear.
> >
> > I understand, git wants people to not explore the available
> > change options and help them make logical decisions rather
> > than pushing them with some unneeded commands.
> >
> >> As Documentation/SubmittingPatches says, let's instruct the code to
> >> "be like so" in imperative mood. E.g., "Enhance the error
> >> message..." instead of "This patch enhances...".
> >
> > Understood that makes sense because nevertheless
> > it is given that I am writing the changes for this patch only.
> >
> >> These were already overly long, but the updated one is way too long
> >> to be read on end-user's terminal. The source lines are overly
> >> long, too.
> >
> > That makes total sense.
> >
> >> to those users who decline the advice, we now show "Please
> >> commit...". That is not what !advice_enabled() should trigger, is
> >> it?
> >
> > Thank you so much for your guidance the advice should not
> > trigger to those who have opted not to see.
> > My code might have misjudged this paradigm.
> >
> >> Also "To move you" -> "To move your".
> >
> > I thought I had fixed this typo. Seems like I didn't.
> > I will remember to be more cautious next time.
> >
> >> Also the advice lost the other possiblity of first committing the
> >> work in progress on the original branch before switching, yet the
> >> new advice message is quite wordy.
> >
> > Absolutely correct this commit does narrow the users vision
> > for exploring.
> >
> >> Also, using "for safe merge" when the user is performing a
> >> "checkout" might be slightly confusing, even if 'stash pop' involves
> >> a merge under the hood.
> >
> > I don't want to sound like a programmed robot but I absolutely
> > agree with the recommendations.
> >
> >> But as I already said, I think the current text may already strike
> >> the right balance between being clear and being concise.
> >
> > Thank you so much for your valuable guidance.
> > If it's possible I want some guidance over the questions written below,
> > As it is well stated by you that the current
> > text is clear enough.
> > Should I still work on this PR from a purely GSoC
> > perspective. Or should I start making my proposal or
> > still work on this PR until my micro project is merged?
> > Because I have already shown I can navigate git project which
> > was the goal of micro projects in the first place.
> >
>
> From the micro-project information [1] for GSoC we have:
>
> The coding part of the microproject should be very small (say, 10-30
> minutes). We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application; we mostly want
> to see that you have a basic level of competence and especially the
> ability to interact with the other Git developers.
>
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
>
> [1]: https://git.github.io/General-Microproject-Information/
>
> [snip]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
2026-03-13 10:49 ` Arsh Srivastava
@ 2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 11:04 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> I understand, git wants people to not explore the available
This was a typo the real text is :
I understand, git wants people to explore the available
On Fri, 13 Mar 2026 at 08:43, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes :
>
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> > Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
> > You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
>
> That makes total sense.
>
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
> > Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
> On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > When a branch switch fails due to local changes and
> > > new users who are not familiar with the error message often
> > > get confused about how to move ahead and resolve the issue as
> > > the previous error message only suggests to commit or stash the changes
> > > but doesn't explain how to do that or what the next steps are.
> >
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> >
> > Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > When a branch switch fails due to local changes, new users who
> > are unfamiliar with the error message often get confused about how
> > to move ahead and resolve the issue.
> >
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is. The _current_ message stops at
> > hinting the commands to be used without giving wordy instructions
> > that are best left to manuals. You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
> >
> > > This patch enhances the error message with more specific
> > > instructions in a concise manner to help users understand
> > > how to resolve the issue and move their local changes
> > > safely to the other branch using stash.
> >
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
> >
> > By the way, the updated message seems much less concise than the
> > original.
> >
> > > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > > - "Please commit your changes or stash them before you switch branches.")
> > > - : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> > > + "To move you local changes safely to the other branch,\n"
> > > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> > > + )
> > > + : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > > + "Please commit your changes or stash them before you switch branches.");
> >
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
> >
> > The original was this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "Please commit your changes or stash them before you switch branches.")
> > : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > Note that when advice is *NOT* enabled, we only gave
> >
> > _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > without any "advise" in the output. That is what !advice_enabled() means.
> >
> > The updated code does this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "To move you local changes safely to the other branch,\n"
> > "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge."
> > )
> > : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "Please commit your changes or stash them before you switch branches.");
> >
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
> >
> > Also "To move you" -> "To move your".
> >
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
> >
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
> >
> > A more concise version might say:
> >
> > Try 'git stash && git checkout <branch> && git stash pop' to carry
> > your changes to the new branch, or commit your work before switching.
> >
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
> >
> > Thanks.
> >
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 10:43 ` Karthik Nayak
2026-03-13 11:02 ` Arsh Srivastava
@ 2026-03-13 22:05 ` Junio C Hamano
1 sibling, 0 replies; 62+ messages in thread
From: Junio C Hamano @ 2026-03-13 22:05 UTC (permalink / raw)
To: Karthik Nayak
Cc: Arsh Srivastava, Arsh Srivastava via GitGitGadget, git,
Phillip Wood, Patrick Steinhardt
Karthik Nayak <karthik.188@gmail.com> writes:
> From the micro-project information [1] for GSoC we have:
>
> The coding part of the microproject should be very small (say, 10-30
> minutes). We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application; we mostly want
> to see that you have a basic level of competence and especially the
> ability to interact with the other Git developers.
>
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
>
> [1]: https://git.github.io/General-Microproject-Information/
Thanks ;-).
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-10 17:09 ` Karthik Nayak
@ 2026-03-14 4:27 ` Konstantin Ryabitsev
0 siblings, 0 replies; 62+ messages in thread
From: Konstantin Ryabitsev @ 2026-03-14 4:27 UTC (permalink / raw)
To: Karthik Nayak
Cc: Junio C Hamano, Arsh Srivastava, Arsh Srivastava via GitGitGadget,
git, Phillip Wood
On Tue, Mar 10, 2026 at 10:09:25AM -0700, Karthik Nayak wrote:
> >> I will rework the patch in that direction and send a v4.
> >>
> >> Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
> >
> > Just a comment by a bystander, but it confuses me quite a lot to see
> > in-body "Subject:" and "Sign-off" in a message that is *not* a patch
> > at all. What are you signing off with this signature?
>
> Tangentially, I know that b4 adds a "Sign-off" to the cover message.
This is a feature, because some subsystems use the cover message as the source
for the merge commit, so the cover message *is* a commit despite not being a
patch. :)
Regards,
--
KR
^ permalink raw reply [flat|nested] 62+ messages in thread
end of thread, other threads:[~2026-03-14 4:27 UTC | newest]
Thread overview: 62+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 8:51 ` [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 2/5] t4052: test for diffstat width when prefix contains ANSI escape codes LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 3/5] repo: remove unnecessary variable shadow K Jayatheerth via GitGitGadget
2026-03-10 8:51 ` [PATCH 4/5] The 13th batch Junio C Hamano via GitGitGadget
2026-03-10 8:51 ` [PATCH 5/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
2026-03-10 10:42 ` Arsh Srivastava
2026-03-10 10:45 ` Arsh Srivastava
2026-03-10 13:36 ` Junio C Hamano
2026-03-10 13:40 ` Arsh Srivastava
2026-03-10 15:40 ` Junio C Hamano
2026-03-10 16:05 ` Arsh Srivastava
2026-03-10 16:08 ` Arsh Srivastava
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
2026-03-10 11:04 ` Arsh Srivastava
2026-03-10 13:16 ` Patrick Steinhardt
2026-03-10 13:36 ` Arsh Srivastava
2026-03-10 14:24 ` Patrick Steinhardt
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-10 13:43 ` Arsh Srivastava
2026-03-10 13:28 ` [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 5/5] File updation [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
2026-03-11 17:06 ` Arsh Srivastava
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
2026-03-12 3:32 ` Arsh Srivastava
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
2026-03-12 16:06 ` Junio C Hamano
2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 18:56 ` Junio C Hamano
2026-03-12 19:03 ` Arsh Srivastava
2026-03-12 19:07 ` Junio C Hamano
2026-03-12 19:12 ` Arsh Srivastava
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
2026-03-12 22:40 ` Junio C Hamano
2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
2026-03-13 11:02 ` Arsh Srivastava
2026-03-13 22:05 ` Junio C Hamano
2026-03-13 10:49 ` Arsh Srivastava
2026-03-13 11:04 ` Arsh Srivastava
2026-03-10 14:31 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Karthik Nayak
2026-03-10 14:37 ` Arsh Srivastava
2026-03-10 14:40 ` Arsh Srivastava
2026-03-10 17:15 ` Karthik Nayak
2026-03-10 18:00 ` Arsh Srivastava
2026-03-10 14:41 ` Arsh Srivastava
2026-03-10 16:48 ` Junio C Hamano
2026-03-10 17:09 ` Karthik Nayak
2026-03-14 4:27 ` Konstantin Ryabitsev
2026-03-10 17:56 ` Arsh Srivastava
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox