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

Re: Git: Unexpected behaviour?

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 14, 2011, 21:33 UTC
Message-ID
<m3k472mltc.fsf@localhost.localdomain>
In-Reply-To
<CAOeW2eEUbvd0eJHjNfbvi9QnDiUO=mFA9rrKsjv8Yu0_QiPgSw@mail.gmail.com>
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
Show 6 quoted lines
> On Sat, Nov 12, 2011 at 11:37 AM, Junio C Hamano <gitster@pobox.com> wrote:
> > "J.V." <jvsrvcs@gmail.com> writes:
> >
> > > OK so "work tree" is a new term for me.  I thought we were in isolated
> > > sandboxes called "branches" and changes made in a branch would stay in
> > > that branch regardless.

That would be the default and only solution if each branch was checked out to a separate working directory.

You can do that in git using git-new-worktree script from contrib.
> > Do not think of "branches" as isolated _sandboxes_.
> >
> > Rather, "branches" are where the independent states are to be _recorded_.

Branches are lines of development, and are about _comitted_ changes. This means that when switching branches "in place", un-committed changes are not on any branch.

Show 12 quoted lines
> I think I was confused about this when learning Git too. I friend of
> mine made the following argument, which I agree with and which I haven
> seen on the list before:
> 
> 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".
The "checkout -m" behavior is unsafe; you can land in a state where it
would be difficult to revert, and could lose your changes.  The
default behavior of switching branches is to carry over changes if it
is safe to do so.
 
> It is obviously too late to change this now, though.

Well, we could in theory add knob that would stash changes when switching to branch, and unstash when switching to branch.

-- 
Jakub Narębski
Previous: Junio C HamanoNext: Alexey Shumkin
Message 12 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.