Git’s EcoFriendly Tree Recycling
PaulC’s Daily Git Teasers: Week1 — Day1 Answer:
Git is a version control system used by software developers and development teams to be a central store for their project code. It allows them to take snapshots of their code as they go, from this they can view the history of changes and their source. Git’s efficient storage methods mean that these repositories of data are smaller than the original fully expanded code and I like to question hows and whys.
During last week I posed a couple of advanced Git Questions, here’s the answer to Day1’s Teaser:
Question1:
If I add a file, commit
Delete that file, commit.
Do I end up reusing the first tree?
Answer1:
First of all we need to examine what is stored within a Git tree and see if anything is time dependent? We can do this by using the ‘cat-file -p’ command to display the content of a tree object:

As we can see in tree 4ac4a0, there is no time sensitive data within the tree itself, so we don’t care when the object for the tree was created so as long as there have been no file object (blob) changes, the tree remains valid so git reuses it.
Let’s check to make sure:
Initial Tree (4ac4a0) from Inital Commit (from above):
Add a file, commit it and then check the new tree 87a0533
(some commands removed for brevity):

Delete the file (git rm), commit the deletion and check the new tree.


Does 4ac4a0 sound familiar?
..the tree remains valid so git reuses it
More Git Answers Later.
Paul
Paul Christie — Version Control Trainer
