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

Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2026, 16:06 UTC
Message-ID
<xmqqms0dghgk.fsf@gitster.g>
In-Reply-To
<pull.2233.v6.git.git.1773288013936.gitgitgadget@gmail.com>
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 9 quoted lines
> 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:
Show 5 quoted lines
> 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.
Previous: Arsh Srivastava via GitGitGadgetNext: Arsh Srivastava
Message 38 of 62 in “Advice on checkout dirty files”
  1. 0/5 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 10, 2026
  2. 1/5 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari via GitGitGadget, Mar 10, 2026
  3. 2/5 t4052: test for diffstat width when prefix contains ANSI escape codesLorenzoPegorari via GitGitGadget, Mar 10, 2026
  4. 3/5 repo: remove unnecessary variable shadowK Jayatheerth via GitGitGadget, Mar 10, 2026
  5. 4/5 The 13th batchJunio C Hamano via GitGitGadget, Mar 10, 2026
  6. 5/5 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  7. Phillip WoodMar 10, 2026
  8. Arsh SrivastavaMar 10, 2026
  9. Arsh SrivastavaMar 10, 2026
  10. Junio C HamanoMar 10, 2026
  11. Arsh SrivastavaMar 10, 2026
  12. Junio C HamanoMar 10, 2026
  13. Arsh SrivastavaMar 10, 2026
  14. Arsh SrivastavaMar 10, 2026
  15. advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  16. Patrick SteinhardtMar 10, 2026
  17. Arsh SrivastavaMar 10, 2026
  18. Patrick SteinhardtMar 10, 2026
  19. 0/2 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 10, 2026
  20. 1/2 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  21. Arsh SrivastavaMar 10, 2026
  22. 2/2 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 10, 2026
  23. 0/5 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 11, 2026
  24. 1/5 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 11, 2026
  25. 2/5 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  26. 3/5 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussionsArsh Srivastava via GitGitGadget, Mar 11, 2026
  27. 4/5 Updating tests and unpack-tress.c [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  28. 5/5 File updation [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  29. Junio C HamanoMar 11, 2026
  30. Arsh SrivastavaMar 11, 2026
  31. 0/3 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 11, 2026
  32. 1/3 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 11, 2026
  33. 2/3 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  34. 3/3 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussionsArsh Srivastava via GitGitGadget, Mar 11, 2026
  35. Junio C HamanoMar 12, 2026
  36. Arsh SrivastavaMar 12, 2026
  37. unpack-trees: suggesting 'git checkout -m' with its repercussionsArsh Srivastava via GitGitGadget, Mar 12, 2026
  38. Junio C HamanoMar 12, 2026
  39. Arsh SrivastavaMar 12, 2026
  40. Junio C HamanoMar 12, 2026
  41. Arsh SrivastavaMar 12, 2026
  42. Junio C HamanoMar 12, 2026
  43. Arsh SrivastavaMar 12, 2026
  44. unpack-trees: suggest using 'git stash' when checkout failsArsh Srivastava via GitGitGadget, Mar 12, 2026
  45. Junio C HamanoMar 12, 2026
  46. Arsh SrivastavaMar 13, 2026
  47. Karthik NayakMar 13, 2026
  48. Arsh SrivastavaMar 13, 2026
  49. Junio C HamanoMar 13, 2026
  50. Arsh SrivastavaMar 13, 2026
  51. Arsh SrivastavaMar 13, 2026
  52. Karthik NayakMar 10, 2026
  53. Arsh SrivastavaMar 10, 2026
  54. Arsh SrivastavaMar 10, 2026
  55. Karthik NayakMar 10, 2026
  56. Arsh SrivastavaMar 10, 2026
  57. Arsh SrivastavaMar 10, 2026
  58. Junio C HamanoMar 10, 2026
  59. Karthik NayakMar 10, 2026
  60. Konstantin RyabitsevMar 14, 2026
  61. Arsh SrivastavaMar 10, 2026
  62. Arsh SrivastavaMar 10, 2026

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

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