threads / discuss / 12455

How are the same file modified on different brances stored physically?

Subject: How are the same file modified on different brances stored physically?

## tl;dr

4 messages between Mar 3, 2008 and Mar 3, 2008.

replies: 3people: 4as markdown or json

amishera· Mar 3, 2008, 08:16 UTC · lore

Hi, I am trying to figure out how stuffs work behind the scene. We know that we can switch branches freely and then work on the switched branch. If the same file is modified on two branches then how are the two copies of the two branches saved?

-- 
View this message in context: http://www.nabble.com/How-are-the-same-file-modified-on-different-brances-stored-physically--tp15799383p15799383.html
Sent from the git mailing list archive at Nabble.com.
Junio C Hamano· Mar 3, 2008, 09:06 UTC · re: amishera · lore

Re: How are the same file modified on different brances stored physically?

amishera <amishera2007@gmail.com> writes:
> I am trying to figure out how stuffs work behind the scene. We know that we
> can switch branches freely and then work on the switched branch. If the same
> file is modified on two branches then how are the two copies of the two
> branches saved?

They are saved separately, and depending on which branch you check out, the appropriate one for that branch is given to you.

Mike Ralphson· Mar 3, 2008, 09:36 UTC · re: amishera · lore

Re: How are the same file modified on different brances stored physically?

On 03/03/2008, amishera <amishera2007@gmail.com> wrote:
>  I am trying to figure out how stuffs work behind the scene. We know that we
>  can switch branches freely and then work on the switched branch. If the same
>  file is modified on two branches then how are the two copies of the two
>  branches saved?
http://eagain.net/articles/git-for-computer-scientists/
May help explain the inner workings.
Jakub Narebski· Mar 3, 2008, 12:10 UTC · re: amishera · lore

Re: How are the same file modified on different brances stored physically?

amishera <amishera2007@gmail.com> writes:
> I am trying to figure out how stuffs work behind the scene. We know
> that we can switch branches freely and then work on the switched
> branch. If the same file is modified on two branches then how are
> the two copies of the two branches saved?

First, read existing bundled and on-line documentation: git(7), "Git User's Manual", "Git Magic", "Git for Computer Scientists", "Git in Nutshell". One of them should explain git concepts to you.

Let's assume for simplicity that project consist of two files, 'foo' and 'bar' in top directory. You have created side branch, using "git checkout -b test-branch" for example. You have modified file 'foo', and committed those changes (either "git add foo; git commit" or "git commit -a". This created three new objects in repository (in object database): a "blob" object containing new contents of file 'foo', new "tree" object with 'link' to old 'bar' and new 'foo', and "commit" object, with given commit message, with 'parent' to previous commit, and with 'tree' to newly created "tree" object. It also advances refs/heads/test-branch to new commit.

Now you switch to previous branch, with "git checkout master". You modify file 'foo' and commit changes. Again, this creates three new objects: "blob", "tree" and "commit". This means that there are three blob objects with contents of 'foo' and one blob object with contents of 'bar'.

Of course after repacking ("git gc") contents for file 'foo' might be stored as base objects (usually largest version) and binary deltas from base. But those are implementation (engine) details.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads