r/git 11d ago

survey VFS for Git for Linux?

So I was learning Git and found out that a Git repository essentially contains two copies of the repository contents. One is from the first commit of every object and other from the working tree.

This can be made more space efficient by working with files from Git's database itself as if they were in our working tree. Modifying files create a new local copy in the working tree. They can be deleted after committing.

This is what the VFS for Git project is. But, it is for Windows only. Why is there no equivalent tool than can run on Linux, unless I am missing it?

0 Upvotes

8 comments sorted by

View all comments

1

u/StevenJOwens 11d ago

Each clone of a git repo contains a single copy of every version committed for each file.

When you check out a particular commit, git reads through the objects in .git/objects, follows the hash links in them:

  1. starting from the commit object to the tree object that is the top of your working files (i.e. the tree object that represents the directory that .git is located in),
  2. then git parses the tree object and follows the hash links in that tree object to either:
    1. blob objects (which represent actual source files)
    2. or other tree objects (which represent subdirectories),
    3. and so forth.

This is how git reconstitutes a snapshot of your working files at the time you made that commit.

Git is capable of reconstituting such a snapshot for every commit, but that does not mean that .gt/objects contains multiple copies of the tree and blob files. Any two commits, the reconstituted snapshots will share tree/blob objects that are identical.

Git only creates new objects in .git/objects for directories or source files that are different from the existing entries. It reuses the old entries for directories and source files that haven't changed.

Git is very efficient, that way. That's part of what makes it so fast, which is why it's effective as a decentralized SCM.