How does git detect that a file has been modified?

后端 未结 4 645
借酒劲吻你
借酒劲吻你 2020-12-01 03:36

How does git detect a file modification so fast?

Does it hash every file in the repo and compare SHA1s? This would take a lot of time, wouldn\'t it?

Or does

4条回答
  •  时光取名叫无心
    2020-12-01 03:46

    Git tries hard to get convinced from the lstat() value alone that the worktree matches the index, because falling back on file contents is very expensive.

    Documentation/technical/racy-git.txt describes what stat fields are used, and how some race conditions due to low mtime granularity are avoided. This article has some more detail.

    stat values aren't tamper-proof, see futimens(3). Git may be fooled into missing a change to a file; that does not compromise the integrity of content-hashing.

提交回复
热议问题