How do branches work in GIT in relation to SVN?

8

It is known that in SVN, when you create a branch (or even a tag ), a copy of the trunk files is made to the folder inside the < strong branches .

Gradually I've been using git and realized that when creating a branch it does not create a copy of any file, but even then I can edit the same file on two different branches, that is, I can keep two or more versions of the same file.

My question is: How does git address this issue? What is the "magic" that git does to keep "multiple versions" of the same file?

    
asked by anonymous 18.09.2015 / 18:26

1 answer

6

The answer lies in documentation .

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

Whenyouhavetwobranches(intheexample,masterandtesting),basicallywehavetwopointers,whichmayormaynotbepointingtothesamecommit,whichinturnpointstoasnapshotofthefile:

ImageSource: link

This is in stark contrast to how most of the manages 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, whereas in Git the process is always instantaneous. Also, because we are recording the parents of the objects when doing commits, finding a good base for doing merge is a task automatically done for us and is usually very easy to do.

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

    
18.09.2015 / 20:53