Git to reuse drops?

Say I wrote a binary file, and then changed it a few commits later, and now I changed it in a new commit.

Out of curiosity, I wondered if git creates a new blob for it? Or does he discover this in history and reuse it? If so, how can this be detected? Check sum?

+6
source share
1 answer

Git will reuse the same blob.

I did a test. I made 3 commits. First I commit the binary, then change the binary and commit it again. Then, finally, I overwrote the file with the original binary code used in the first commit and restarted it.

The contents of binary files in the 1st and 3rd transactions are the same. Each commit is HEAD of the following branches:

1st commit: "FIRST". 2nd commit: "SECOND". Third fix: "master"

Then, if you run "git cat-file -p FIRST ^ {tree}", it displays the hash of the binary.

$ git cat-file -p FIRST^{tree} 100644 blob ec049240a47b472bd7c31d1fa27118c4fe2f1229 test.db3 $ git cat-file -p SECOND^{tree} 100644 blob a47bb3727e5aefe3ec386bec5520f3e4ffb3a4c5 test.db3 $ git cat-file -p master^{tree} 100644 blob ec049240a47b472bd7c31d1fa27118c4fe2f1229 test.db3 

You will find that the hash code of the 1st and 3rd commit blocks is the same.

Git is smart enough to check if a blob exists for a hash code and reuse that blob if it is found.

+7
source

Source: https://habr.com/ru/post/975400/


All Articles