{"thread":{"id":"19557","subject":"What is the mechanism of a git checkout?","startedAt":"2009-05-28T15:21:59Z","lastAt":"2009-05-29T09:05:27Z","messageCount":4,"participants":["mastermindxs","Peter Harris","Sitaram Chamarty","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114926","messageId":"23764024.post@talk.nabble.com","threadId":"19557","inReplyTo":null,"subject":"What is the mechanism of a git checkout?","fromName":"mastermindxs","fromEmail":"mastermindxs@gmail.com","sentAt":"2009-05-28T15:21:59Z","receivedAt":"2009-05-28T15:21:59Z","isPatch":false,"sender":{"key":"mastermindxs@gmail.com","avatar":null},"body":"\ndoes a git checkout pull the contents of a branch? how does it physically\nseparate files in your working directory from other branches? \n\nThe speed of which it works leads me to the logical conclusion that the\nfiles in the working directory are all there for all branches and git simply\nonly shows you the files of the active branch.\n\nCan anyone shed more light on the underlying mechanisms of git checkout\nmaybe even branch and merge as well?\n\nthanks\n-diego\nwww.greyrobot.com\n-- \nView this message in context: http://www.nabble.com/What-is-the-mechanism-of-a-git-checkout--tp23764024p23764024.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"114929","messageId":"eaa105840905280926k482b6a3an82836c123cc38f6f@mail.gmail.com","threadId":"19557","inReplyTo":"23764024.post@talk.nabble.com","subject":"Re: What is the mechanism of a git checkout?","fromName":"Peter Harris","fromEmail":"git@peter.is-a-geek.org","sentAt":"2009-05-28T16:26:53Z","receivedAt":"2009-05-28T16:26:53Z","isPatch":false,"sender":{"key":"git@peter.is-a-geek.org","avatar":null},"body":"On Thu, May 28, 2009 at 11:21 AM, mastermindxs wrote:\n>\n> Can anyone shed more light on the underlying mechanisms of git checkout\n> maybe even branch and merge as well?\n\nThis may help you understand Git: http://www.youtube.com/watch?v=8dhZ9BXQgc4\n\nAlso: http://eagain.net/articles/git-for-computer-scientists/\n\nPeter Harris\n"},{"id":"114978","messageId":"slrnh1udov.6ls.sitaramc@sitaramc.homelinux.net","threadId":"19557","inReplyTo":"23764024.post@talk.nabble.com","subject":"Re: What is the mechanism of a git checkout?","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-05-29T01:15:12Z","receivedAt":"2009-05-29T01:15:12Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-05-28 15:21:59, mastermindxs <mastermindxs@gmail.com> wrote:\n>\n> does a git checkout pull the contents of a branch? how does it physically\n> separate files in your working directory from other branches? \n>\n> The speed of which it works leads me to the logical conclusion that the\n> files in the working directory are all there for all branches and git simply\n> only shows you the files of the active branch.\n>\n> Can anyone shed more light on the underlying mechanisms of git checkout\n> maybe even branch and merge as well?\n\nI explain it as below when I get asked this question.  It's\na simplified answer but largely correct, I believe.\nCorrections from git.gods welcome :-)\n\nWhen you checkout a branch, you are moving from a \"before\"\nbranch to an \"after\" branch.  git does this:\n\n  - untracked files are never touched; the rest of this\n    discussion does not apply to them\n\n  - files which do NOT show up in \"git status\" (ie unchanged\n    with respect to the \"before\" branch) are changed as per\n    their status in the \"after\" branch.\n\n    - if they exist in the \"after\" branch, and are the same\n      as in the \"before\" branch, they are left alone\n\n      This is where all the speed you see comes from!\n\n    - if they exist in the \"after\" branch, and they are\n      **different** than in the \"before\" branch, they are\n      checked out from the \"after\" branch\n\n      This is the bulk of the disk activity; if there are\n      few of these, it's fast enough for you think nothing\n      is actually happening ;-)\n\n    - if they do not exist in the \"after\" branch, they are\n      deleted\n\n  - files that do show up in \"git status\" in the \"before\"\n    branch, are either modified or staged.\n    \n    - if the \"before\" branch version is the same as the\n      \"after\" branch version, that also is not touched.  In\n      the new branch, running \"git status\" will show you the\n      same files.\n\n    - if the \"before\" branch version and the \"after\" branch\n      version are *not* the same, git would lose your local\n      (uncommitted) changes, so it refuses to do the\n      checkout and stays where it is.\n"},{"id":"114995","messageId":"m3hbz4b7ov.fsf@localhost.localdomain","threadId":"19557","inReplyTo":"slrnh1udov.6ls.sitaramc@sitaramc.homelinux.net","subject":"Re: What is the mechanism of a git checkout?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-05-29T09:05:27Z","receivedAt":"2009-05-29T09:05:27Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Sitaram Chamarty <sitaramc@gmail.com> writes:\n> On 2009-05-28 15:21:59, mastermindxs <mastermindxs@gmail.com> wrote:\n> >\n> > does a git checkout pull the contents of a branch? how does it\n> > physically separate files in your working directory from other\n> > branches?\n> >\n> > The speed of which it works leads me to the logical conclusion\n> > that the files in the working directory are all there for all\n> > branches and git simply only shows you the files of the active\n> > branch.\n> >\n> > Can anyone shed more light on the underlying mechanisms of git\n> > checkout maybe even branch and merge as well?\n> \n> I explain it as below when I get asked this question.  It's\n> a simplified answer but largely correct, I believe.\n\n[...]\n>   - files that do show up in \"git status\" in the \"before\"\n>     branch, are either modified or staged.\n>     \n>     - if the \"before\" branch version is the same as the\n>       \"after\" branch version, that also is not touched.  In\n>       the new branch, running \"git status\" will show you the\n>       same files.\n> \n>     - if the \"before\" branch version and the \"after\" branch\n>       version are *not* the same, git would lose your local\n>       (uncommitted) changes, so it refuses to do the\n>       checkout and stays where it is.\n\nIn which case (there is file which is different in \"before\" and\n\"after\", and which is modified in working area) you can ask git to try\nto 'move' (merge) changes from \"before\" to \"after\" version of a file\nwith '-m' / --merge option, see git-checkout(1):\n\n  git checkout -m after\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}