How does git track file changes internally?

前端 未结 5 1975
孤街浪徒
孤街浪徒 2021-02-12 16:10

Could somebody explain how git knows internally that files X, Y and Z have changed? What is the process behind the scenes that recognizes when a file has not yet been added or h

5条回答
  •  -上瘾入骨i
    2021-02-12 16:31

    You can find your answer in the free book Pro-Git on chapter Git Internals

    This chapter explains how git works behind the hood.

    As Leo stated, git checks the SHA1 of the files to see if it has changed you can check it like this (Taken from Git Internals):

    $ echo 'version 1' > test.txt
    $ git hash-object -w test.txt
    83baae61804e65cc73a7201a7252750c76066a30
    

    Then, write some new content to the file, and save it again:

    $ echo 'version 2' > test.txt
    $ git hash-object -w test.txt
    1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
    

提交回复
热议问题