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

Re: Git: Unexpected behaviour?

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 14, 2011, 20:55 UTC
Message-ID
<7vr51aifug.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAOeW2eEUbvd0eJHjNfbvi9QnDiUO=mFA9rrKsjv8Yu0_QiPgSw@mail.gmail.com>
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
Show 8 quoted lines
> Either you want the modifications to stay on the branch, or you want
> them to carry over to the branch you are checking out. In the former
> case, you would want Git to fail if there are modifications (that you
> might have forgotten you made). In the latter case, you would want
> "git checkout -m". The current behavior is somewhere in between. It is
> not clear to me if there is a use case where the current behavior is
> better (from the user's point of view) than either failing or
> "checkout -m".

Current behaviour is deliberately made safe because "checkout -m" may end up forcing you to resolve a 3-way conflict you may not be prepared to do correctly at your first attempt. Stopping and refusing to check out the other branch gives you the choice to create a temporary stash-away commit either on a current branch, or a temporary branch you create with "git checkout -b temp && git commit" before switching to the target branch to attempt to port the change over with "git cherry-pick @{-1}", which you _can_ redo if you screw up conflict resolution and want to start over. If you are confident that your local changes are trivial that you can reproduce it even if you screw up your conflict resolution attempt, then you can choose to run "checkout -m". If we made it the default, you will lose this safety.

On the other hand, if you do *not* want to carry over the change when checking out a different branch, you can easily stash-away the changes.

Previous: Martin von ZweigbergkNext: Jakub Narebski
Message 11 of 14 in “Git: Unexpected behaviour?”
  1. JvsrvcsNov 11, 2011
  2. Carlos Martín NietoNov 11, 2011
  3. JvsrvcsNov 11, 2011
  4. Taylor HedbergNov 11, 2011
  5. Gelonida NNov 11, 2011
  6. Chris PackhamNov 11, 2011
  7. J.V.Nov 12, 2011
  8. Chris PackhamNov 12, 2011
  9. Junio C HamanoNov 12, 2011
  10. Martin von ZweigbergkNov 14, 2011
  11. Junio C HamanoNov 14, 2011
  12. Jakub NarebskiNov 14, 2011
  13. Alexey ShumkinNov 12, 2011
  14. Eugene SajineNov 11, 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.