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

Re: [BUG] git checkout <branch> allowed with uncommitted changes

From
Jeff King <peff@peff.net>
Date
Oct 14, 2011, 01:38 UTC
Message-ID
<20111014013830.GA7258@sigill.intra.peff.net>
In-Reply-To
<loom.20111013T203610-130@post.gmane.org>
On Thu, Oct 13, 2011 at 06:56:14PM +0000, arQon wrote:
Show 5 quoted lines
> I'll give a shot, though I don't know how good it'll be. Off the top of my
> head, I don't see any good way to explain the inconsistency with LOCAL CHANGES
> sometimes preventing switches and sometimes not, based on what is to the user
> an arbitrary set of rules that has nothing to do with the *current state* of
> the worktree, but rather the state of those files in prior commits.

The rules are fairly straightforward. You are moving from branch A to branch B. If path X is not changed going from A to B, git will not touch it, whether or not you have local changes. If path X is changed going from A to B, then git will refuse the checkout, and you have the option of:

  1. checkout -f: overwrite your local changes with what's in B
  2. checkout -m: merge your changes with what's in B (using A as a
                  common ancestor)
> But sure, I'll see if I can come up with something. If nothing else,
> having the manpage at least explain what "M" means; that it can be
> potentially disastrous; and what you need to do to avoid it, would be
> a definite plus.

You keep saying things like "disastrous". Git's rules are specifically designed to be as flexible as possible without allowing the checkout command to cause data loss.

Do you actually have a case that causes irrecoverable data loss?

Note that I don't count "these changes were based on A, now they are based on B" as data loss. Your file content is still completely intact, and if you want to make them based on "A" again, you just need to "git checkout A" again.

-Peff
Previous: arQonNext: Holger Hellmuth
Message 21 of 36 in “[BUG] git checkout <branch> allowed with uncommitted changes”
  1. arQonOct 13, 2011
  2. Nguyen Thai Ngoc DuyOct 13, 2011
  3. Alexey ShumkinOct 13, 2011
  4. arQonOct 13, 2011
  5. Andreas EricssonOct 13, 2011
  6. arQonOct 13, 2011
  7. Carlos Martín NietoOct 13, 2011
  8. arQonOct 13, 2011
  9. Alexey ShumkinOct 13, 2011
  10. Jakub NarebskiOct 13, 2011
  11. arQonOct 13, 2011
  12. Carlos Martín NietoOct 13, 2011
  13. arQonOct 13, 2011
  14. Alexey ShumkinOct 13, 2011
  15. Alexey ShumkinOct 14, 2011
  16. Holger HellmuthOct 13, 2011
  17. Carlos Martín NietoOct 13, 2011
  18. arQonOct 13, 2011
  19. Junio C HamanoOct 13, 2011
  20. arQonOct 13, 2011
  21. Jeff KingOct 14, 2011
  22. Holger HellmuthOct 14, 2011
  23. Victor EngmarkOct 14, 2011
  24. arQonOct 16, 2011
  25. Junio C HamanoOct 16, 2011
  26. Holger HellmuthOct 16, 2011
  27. Carlos Martín NietoOct 13, 2011
  28. Sergei OrganovOct 13, 2011
  29. PJ WeisbergOct 13, 2011
  30. Holger HellmuthOct 13, 2011
  31. arQonOct 13, 2011
  32. Holger HellmuthOct 13, 2011
  33. Victor EngmarkOct 13, 2011
  34. arQonOct 13, 2011
  35. Victor EngmarkOct 14, 2011
  36. Michael J GruberOct 13, 2011

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.