git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* What is the mechanism of a git checkout?
@ 2009-05-28 15:21 mastermindxs
  2009-05-28 16:26 ` Peter Harris
  2009-05-29  1:15 ` Sitaram Chamarty
  0 siblings, 2 replies; 4+ messages in thread
From: mastermindxs @ 2009-05-28 15:21 UTC (permalink / raw)
  To: git


does a git checkout pull the contents of a branch? how does it physically
separate files in your working directory from other branches? 

The speed of which it works leads me to the logical conclusion that the
files in the working directory are all there for all branches and git simply
only shows you the files of the active branch.

Can anyone shed more light on the underlying mechanisms of git checkout
maybe even branch and merge as well?

thanks
-diego
www.greyrobot.com
-- 
View this message in context: http://www.nabble.com/What-is-the-mechanism-of-a-git-checkout--tp23764024p23764024.html
Sent from the git mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What is the mechanism of a git checkout?
  2009-05-28 15:21 What is the mechanism of a git checkout? mastermindxs
@ 2009-05-28 16:26 ` Peter Harris
  2009-05-29  1:15 ` Sitaram Chamarty
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Harris @ 2009-05-28 16:26 UTC (permalink / raw)
  To: mastermindxs; +Cc: git

On Thu, May 28, 2009 at 11:21 AM, mastermindxs wrote:
>
> Can anyone shed more light on the underlying mechanisms of git checkout
> maybe even branch and merge as well?

This may help you understand Git: http://www.youtube.com/watch?v=8dhZ9BXQgc4

Also: http://eagain.net/articles/git-for-computer-scientists/

Peter Harris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What is the mechanism of a git checkout?
  2009-05-28 15:21 What is the mechanism of a git checkout? mastermindxs
  2009-05-28 16:26 ` Peter Harris
@ 2009-05-29  1:15 ` Sitaram Chamarty
  2009-05-29  9:05   ` Jakub Narebski
  1 sibling, 1 reply; 4+ messages in thread
From: Sitaram Chamarty @ 2009-05-29  1:15 UTC (permalink / raw)
  To: git

On 2009-05-28 15:21:59, mastermindxs <mastermindxs@gmail.com> wrote:
>
> does a git checkout pull the contents of a branch? how does it physically
> separate files in your working directory from other branches? 
>
> The speed of which it works leads me to the logical conclusion that the
> files in the working directory are all there for all branches and git simply
> only shows you the files of the active branch.
>
> Can anyone shed more light on the underlying mechanisms of git checkout
> maybe even branch and merge as well?

I explain it as below when I get asked this question.  It's
a simplified answer but largely correct, I believe.
Corrections from git.gods welcome :-)

When you checkout a branch, you are moving from a "before"
branch to an "after" branch.  git does this:

  - untracked files are never touched; the rest of this
    discussion does not apply to them

  - files which do NOT show up in "git status" (ie unchanged
    with respect to the "before" branch) are changed as per
    their status in the "after" branch.

    - if they exist in the "after" branch, and are the same
      as in the "before" branch, they are left alone

      This is where all the speed you see comes from!

    - if they exist in the "after" branch, and they are
      **different** than in the "before" branch, they are
      checked out from the "after" branch

      This is the bulk of the disk activity; if there are
      few of these, it's fast enough for you think nothing
      is actually happening ;-)

    - if they do not exist in the "after" branch, they are
      deleted

  - files that do show up in "git status" in the "before"
    branch, are either modified or staged.
    
    - if the "before" branch version is the same as the
      "after" branch version, that also is not touched.  In
      the new branch, running "git status" will show you the
      same files.

    - if the "before" branch version and the "after" branch
      version are *not* the same, git would lose your local
      (uncommitted) changes, so it refuses to do the
      checkout and stays where it is.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What is the mechanism of a git checkout?
  2009-05-29  1:15 ` Sitaram Chamarty
@ 2009-05-29  9:05   ` Jakub Narebski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2009-05-29  9:05 UTC (permalink / raw)
  To: Sitaram Chamarty; +Cc: git

Sitaram Chamarty <sitaramc@gmail.com> writes:
> On 2009-05-28 15:21:59, mastermindxs <mastermindxs@gmail.com> wrote:
> >
> > does a git checkout pull the contents of a branch? how does it
> > physically separate files in your working directory from other
> > branches?
> >
> > The speed of which it works leads me to the logical conclusion
> > that the files in the working directory are all there for all
> > branches and git simply only shows you the files of the active
> > branch.
> >
> > Can anyone shed more light on the underlying mechanisms of git
> > checkout maybe even branch and merge as well?
> 
> I explain it as below when I get asked this question.  It's
> a simplified answer but largely correct, I believe.

[...]
>   - files that do show up in "git status" in the "before"
>     branch, are either modified or staged.
>     
>     - if the "before" branch version is the same as the
>       "after" branch version, that also is not touched.  In
>       the new branch, running "git status" will show you the
>       same files.
> 
>     - if the "before" branch version and the "after" branch
>       version are *not* the same, git would lose your local
>       (uncommitted) changes, so it refuses to do the
>       checkout and stays where it is.

In which case (there is file which is different in "before" and
"after", and which is modified in working area) you can ask git to try
to 'move' (merge) changes from "before" to "after" version of a file
with '-m' / --merge option, see git-checkout(1):

  git checkout -m after

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-29  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-28 15:21 What is the mechanism of a git checkout? mastermindxs
2009-05-28 16:26 ` Peter Harris
2009-05-29  1:15 ` Sitaram Chamarty
2009-05-29  9:05   ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).