How do branches in GIT work in relation to SVN?

Asked

Viewed 153 times

8

It is known that in the SVN, when one creates a branch (or even a tag), a copy of all the files of trunk to the folder inside the directory branches.

Little by little I’ve been using git and I realized that by creating a branch it does not copy any file, but even so I can edit the same file in two different branches, ie I can keep two, or more versions of the same file.

My question is: Like the git treats this question? What is the "magic" that the git does to be able to maintain "multiple versions" of the same file?

  • I don’t know the details so I won’t answer but he works with deltas of what you modify and that’s all it needs. It calculates the state of the branch instead of having copies.

  • I confess that I was already waiting for a reply from you @bigown

  • @Jéfersonbueno Still waiting for the perfect answer?

  • @Fellipesoares Yes, it is customary for me to take some time to accept an answer. I like to give opportunities if more people want to answer

  • @Jéfersonbueno I asked just to know if I should research more about =) Thanks.

  • @Fellipesoares Your answer is clear, of course edits/ improvements will be well accepted. But, really, it’s just a matter of custom.

Show 1 more comment

1 answer

6


The answer is in documentation.

At each commit, are created snapshots of that same file in the directory of Git. As branches are like pointers that always point to a snapshot. In the example below, we see the branch master.

Fonte: https://git-scm.com/

When you have two branches (in the example, master and testing, basically, we have two pointers, which may or may not be pointing to the same commit, which in turn points to a snapshot of the archive:

Fonte: https://git-scm.com/

Image source: https://git-scm.com/

This is in sharp contrast to the shape with which most of the manage branches, which involves copying all project files to a second directory.

This can take several seconds or even minutes, depending on the size of the project, while at Git the process is always instantaneous. Also, because we are recording the parents of objects when we do commits, find a good basis to do the merge is a task done automatically for us and is usually very easy to do.

These resources help encourage developers to create and use branches frequently.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.