2 Comments

Good read. Just a question:

According to this explanation, git is storing all the versions of all the files namely A, A1, A2, B, B1, B2, C, C1, C2 and C3. Which means there is lot more storage used by git. But I dont see my git directory being that huge is size. So where exactly these version of files are stored?

Expand full comment
author

Good question Himanshu. Git saves all the changes in the folder '.git'. If you see any git enabled folder, you can see that folder.

Then, as I mentioned in the post, whenever you do a commit, Git takes a full copy of the file system and bundles it and verifies it by a checksum. So each commit is unique.

So when Git sees a modified file, then Git creates a new file with the changes in the newer version. And the files which are not modified are not newly created, it is just pointed back to the older version of the file.

As you can see, File B is created in version 1. Then in version 2 and in version 3, File B is not newly created. It's just pointed back to the older version. And at the same time, File A with changes are newly created as File A1 in version 2. This is how Git manages changes.

With this technique, Git is not creating the entire file system for every commit. This helps in saving more storage. And if you look at the larger projects for a longer time period, you can see that file system size will be increased over the period of time.

Hope this answers your question. If you got any other doubts, just reply to this one :)

Expand full comment