Skip to content

Commit e644634

Browse files
committed
advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
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
1 parent eb5639d commit e644634

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

advice.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)
327327
fprintf(stderr, "\t%s\n", item->string);
328328

329329
advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
330-
_("You can save your local changes before switching by running:\n"
330+
_("To carry your local changes over to the new branch, use:\n"
331331
"\n"
332-
"\tgit stash push\n"
333-
"\n"
334-
"Then restore them after switching with:\n"
335-
"\n"
336-
"\tgit stash pop\n"
337-
"\n"
338-
"Or to discard your local changes, use:\n"
339-
"\n"
340-
"\tgit checkout -- <file>"));
332+
"\tgit checkout -m <branch>\n"
333+
));
341334
}

0 commit comments

Comments
 (0)