git如何检测文件已被修改? [英] How does git detect that a file has been modified?

查看:2141
本文介绍了git如何检测文件已被修改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git如何快速检测文件修改?



它是否对散列表中的每个文件进行散列并比较SHA1?这会花费很多时间,不是吗?



或者它比较 atime ctime mtime

解决方案

Git很难从lstat()值中唯一确信工作树匹配索引,因为回退文件内容非常昂贵。



Documentation / technical / racy-git.txt 描述什么样的统计字段被使用,以及如何避免由于低时间粒度造成的一些竞争条件。 这篇文章有更多的细节



值不是防篡改的,参见futimens(3)。 Git可能会被愚弄到丢失对文件的更改;这不会影响内容散列的完整性。


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 it compare atime, ctime or mtime?

解决方案

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.

这篇关于git如何检测文件已被修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆