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

Re: Git branches - confusing behavior

From
MMMatt Seitz (matseitz) <matseitz@cisco.com>
Date
Jun 30, 2008, 07:23 UTC
Message-ID
<70952A932255A2489522275A628B97C3072392FA@xmb-sjc-233.amer.cisco.com>
On May 11, 3:58 am, mitya <dima.ka...@gmail.com> wrote:
Show 14 quoted lines
> I started with the following steps:
> 
> > git-svn clonehttp://svn.test.org/test/trunk
> > cd trunk
> > git branch test_branch
> > git checkout test_branch
> > vi somefile
> 
> However, when I execute 'git checkout master', I get:
> M       somefile
> Switched to branch "master"
> 
> Basically I see that the same file I edited on the 'test_branch'
> branch appears to be modified on the 'master' branch as well. 
I was also confused by this behavior.  I think this is a documentation issue.  In the "man" page for "git-checkout", the "Description" section says:
"...this command switches branches by updating the index and working tree to reflect the specified branch...".
This led me to believe that all files in the working tree would be updated to match the last commit in the specified branch.  The "Description" section doesn't mention any exceptions, such as files that have been modified but not committed in the current branch.  
There are some clues that this is the intended behavior in the descriptions of the "-f" and "-m" options, and in the "After working in the wrong branch..." example.  But it was not clear to me from reading the "man" page (and the "gittutorial" and the "Git User's Guide") that this behavior was correct and intended. 
I think it would be helpful in the "Description" section of the "man" page to elaborate on how git updates the working tree to reflect the specified branch.  This could include documenting the default handling of files that have been modified in the current branch.  A rationale for the behavior would also be helpful.  This might have prevented my confusion when first encountering this issue.
  
--
Matt Seitz
Manager, File System Virtualization
Cisco Systems, Inc.
.:|:.:|:. 
Message 1 of 1 in “Re: Git branches - confusing behavior”
  1. Matt Seitz (matseitz)Jun 30, 2008

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.