{"thread":{"id":"12455","subject":"How are the same file modified on different brances stored physically?","startedAt":"2008-03-03T08:16:49Z","lastAt":"2008-03-03T12:10:42Z","messageCount":4,"participants":["amishera","Junio C Hamano","Mike Ralphson","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"70763","messageId":"15799383.post@talk.nabble.com","threadId":"12455","inReplyTo":null,"subject":"How are the same file modified on different brances stored physically?","fromName":"amishera","fromEmail":"amishera2007@gmail.com","sentAt":"2008-03-03T08:16:49Z","receivedAt":"2008-03-03T08:16:49Z","isPatch":false,"sender":{"key":"amishera2007@gmail.com","avatar":null},"body":"\nHi,\nI am trying to figure out how stuffs work behind the scene. We know that we\ncan switch branches freely and then work on the switched branch. If the same\nfile is modified on two branches then how are the two copies of the two\nbranches saved?\n-- \nView this message in context: http://www.nabble.com/How-are-the-same-file-modified-on-different-brances-stored-physically--tp15799383p15799383.html\nSent from the git mailing list archive at Nabble.com.\n\n"},{"id":"70765","messageId":"7vskz8i3cy.fsf@gitster.siamese.dyndns.org","threadId":"12455","inReplyTo":"15799383.post@talk.nabble.com","subject":"Re: How are the same file modified on different brances stored physically?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-03T09:06:05Z","receivedAt":"2008-03-03T09:06:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"amishera <amishera2007@gmail.com> writes:\n\n> I am trying to figure out how stuffs work behind the scene. We know that we\n> can switch branches freely and then work on the switched branch. If the same\n> file is modified on two branches then how are the two copies of the two\n> branches saved?\n\nThey are saved separately, and depending on which branch you check out, the\nappropriate one for that branch is given to you.\n"},{"id":"70767","messageId":"e2b179460803030136s16d9c54by7c7a4c58682e0fea@mail.gmail.com","threadId":"12455","inReplyTo":"15799383.post@talk.nabble.com","subject":"Re: How are the same file modified on different brances stored physically?","fromName":"Mike Ralphson","fromEmail":"mike.ralphson@gmail.com","sentAt":"2008-03-03T09:36:46Z","receivedAt":"2008-03-03T09:36:46Z","isPatch":false,"sender":{"key":"mike.ralphson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/21603?v=4"},"body":"On 03/03/2008, amishera <amishera2007@gmail.com> wrote:\n>  I am trying to figure out how stuffs work behind the scene. We know that we\n>  can switch branches freely and then work on the switched branch. If the same\n>  file is modified on two branches then how are the two copies of the two\n>  branches saved?\n\nhttp://eagain.net/articles/git-for-computer-scientists/\n\nMay help explain the inner workings.\n"},{"id":"70777","messageId":"m3zltghut1.fsf@localhost.localdomain","threadId":"12455","inReplyTo":"15799383.post@talk.nabble.com","subject":"Re: How are the same file modified on different brances stored physically?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-03T12:10:42Z","receivedAt":"2008-03-03T12:10:42Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"amishera <amishera2007@gmail.com> writes:\n\n> I am trying to figure out how stuffs work behind the scene. We know\n> that we can switch branches freely and then work on the switched\n> branch. If the same file is modified on two branches then how are\n> the two copies of the two branches saved?\n\nFirst, read existing bundled and on-line documentation: git(7), \"Git\nUser's Manual\", \"Git Magic\", \"Git for Computer Scientists\", \"Git in\nNutshell\".  One of them should explain git concepts to you.\n\nLet's assume for simplicity that project consist of two files, 'foo'\nand 'bar' in top directory.  You have created side branch, using\n\"git checkout -b test-branch\" for example. You have modified file\n'foo', and committed those changes (either \"git add foo; git commit\"\nor \"git commit -a\".  This created three new objects in repository (in\nobject database): a \"blob\" object containing new contents of file\n'foo', new \"tree\" object with 'link' to old 'bar' and new 'foo', and\n\"commit\" object, with given commit message, with 'parent' to previous\ncommit, and with 'tree' to newly created \"tree\" object.  It also\nadvances refs/heads/test-branch to new commit.\n\nNow you switch to previous branch, with \"git checkout master\".  You\nmodify file 'foo' and commit changes.  Again, this creates three new\nobjects: \"blob\", \"tree\" and \"commit\".  This means that there are three\nblob objects with contents of 'foo' and one blob object with contents\nof 'bar'.\n\nOf course after repacking (\"git gc\") contents for file 'foo' might be\nstored as base objects (usually largest version) and binary deltas\nfrom base.  But those are implementation (engine) details.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}