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

Re: Better cooperation between checkouts and stashing

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 27, 2010, 21:51 UTC
Message-ID
<7vr5o6s5xf.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4B898F97.90706@web.de>
Markus Elfring <Markus.Elfring@web.de> writes:
Show 5 quoted lines
>> If you are starting from "if your work tree is dirty, you MUST stash
>> before checking out another branch", the suggestion is understandable.
>> But the thing is, that starting point is not quite correct.
> ...
> When will it not be needed to reset the work tree to the last corresponding commit?
A response to a month old message is a blast from the past ;-).

The answer is "almost always" for me. IOW, if checkout stashed away my local changes, it would be very inconvenient.

It is important to understand that a local change does not belong to your current branch (it does not belong to _any_ branch). It belongs to you, and you can take it around while switching between branches. And that is a big time-saving feature.

This lets you work like this:
 - You are reading a mailing list message that asks for help, and you know
   the solution---you can give the help real quick.
 - You hack in whatever branch that happen to be checked out.  The change
   is perfect, it works.
 - The branch you happen to have checked out was 'next', but the solution
   is a bugfix, and should go to 'maint'.

Now, at this point, you want to checkout 'maint' without losing your local change. The paths you touched with your quick fix are often not different between the two branches, and "checkout maint" will checkout the branch while keeping your local changes intact. All that is left for you to do is to run another round of test to make sure that your fix didn't depend on anything not in 'maint' and commit the change with appropriate log message, and then you can go back to whatever you were doing with "checkout next".

When the change involves paths that were touched between 'maint' and 'next', of course you won't be able to switch without merging the local change to the difference between 'next' and 'maint'. There are a few workflows to deal with such a case, and the easiest is "checkout -m", if you are confident that you can resolve it.

In a case where "checkout -m" would result in a conflict too big to resolve, the original fix you made would not be applicable to 'maint' (iow, you should have solved it differently starting from 'maint'), and you may end up doing "reset --hard" and start from scratch, but that is a rare worst case.

I said it is rare, because you would notice, while doing the "quick fix" based on 'next' codebase, that the code you are touching have changed since 'maint' and won't be applicable to its final destination (by that time you know you are "fixing"), and you won't waste too much time continuing to work in a checkout of 'next'.

Previous: Markus ElfringNext: Markus Elfring
Message 14 of 56 in “Better cooperation between checkouts and stashing”
  1. Markus ElfringFeb 1, 2010
  2. Junio C HamanoFeb 1, 2010
  3. Markus ElfringFeb 1, 2010
  4. Eugene SajineFeb 1, 2010
  5. Petr BaudisFeb 2, 2010
  6. Markus ElfringFeb 2, 2010
  7. Petr BaudisFeb 2, 2010
  8. Markus ElfringFeb 9, 2010
  9. Junio C HamanoFeb 9, 2010
  10. Markus ElfringFeb 9, 2010
  11. Markus ElfringFeb 18, 2010
  12. Junio C HamanoFeb 18, 2010
  13. Markus ElfringFeb 27, 2010
  14. Junio C HamanoFeb 27, 2010
  15. Markus ElfringFeb 28, 2010
  16. Michael WittenFeb 28, 2010
  17. Markus ElfringMar 1, 2010
  18. Michael WittenMar 1, 2010
  19. Junio C HamanoMar 1, 2010
  20. Michael WittenMar 1, 2010
  21. Markus ElfringMar 1, 2010
  22. Junio C HamanoMar 1, 2010
  23. Markus ElfringMar 1, 2010
  24. Michael WittenMar 2, 2010
  25. Markus ElfringMar 2, 2010
  26. Junio C HamanoMar 2, 2010
  27. Markus ElfringMar 3, 2010
  28. Michael WittenMar 4, 2010
  29. Markus ElfringMar 4, 2010
  30. Markus ElfringMar 2, 2010
  31. Junio C HamanoMar 2, 2010
  32. Markus ElfringMar 3, 2010
  33. Markus ElfringMar 17, 2010
  34. Avery PennarunMar 17, 2010
  35. Markus ElfringMar 17, 2010
  36. Junio C HamanoMar 17, 2010
  37. Markus ElfringMar 17, 2010
  38. Junio C HamanoMar 17, 2010
  39. Michael WittenMar 17, 2010
  40. Junio C HamanoMar 17, 2010
  41. Markus ElfringMar 18, 2010
  42. Avery PennarunMar 18, 2010
  43. Michael WittenMar 18, 2010
  44. Avery PennarunMar 18, 2010
  45. Markus ElfringMar 19, 2010
  46. Avery PennarunMar 19, 2010
  47. Markus ElfringMar 20, 2010
  48. Markus ElfringMar 19, 2010
  49. Markus ElfringMar 30, 2010
  50. Junio C HamanoMar 30, 2010
  51. Ramkumar RamachandraMar 31, 2010
  52. Junio C HamanoApr 1, 2010
  53. Ramkumar RamachandraApr 1, 2010
  54. Markus ElfringApr 1, 2010
  55. Markus ElfringApr 10, 2010
  56. Junio C HamanoApr 10, 2010

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.