Reputation: 23
I was wondering where Git saves all the data from branches. Everytime you switch a branch all the data is put back in-place and data from another specific branch is just removed.
Does it take longer on a slower CPU/HDD to bring back the data from another branch? How does the internal work?
Upvotes: 2
Views: 138
Reputation: 526613
Git stores file data in objects called "blobs". Those are stored in the .git/objects
directory within the repository.
The mapping of blobs into the directory structure is done by objects called "trees", which are recursive - one tree can refer to other trees in the case of subdirectories.
A commit in turn references a specific tree that is the state of the root directory of the repository at the time it was committed.
A branch is simply a pointer to a specific commit.
When you check out a branch, Git goes and looks up the commit that it points to. From there, it loads the tree(s) referenced by the commit, and from those, it gets the precise blobs that should be matched to each location in the tree. It then loads the contents of those blobs into the proper file paths.
To assist with this, it uses the index, which is a mapping of file states to paths in the directory tree, along with hashes of their content and a record of their last modification time. Git uses those hashes and mtimes to quickly identify which files need to be updated, and loads the proper contents.
Any kind of work will take longer on a slower CPU+HDD, because it's not specifically bound by time. It will use as much CPU/disk speed as possible. That said, Git is fairly efficient, so unless you have significant numbers of files or very large file content changes (or a very slow devices), it will generally go quite quickly.
Upvotes: 3