Git如何为它的斑点记录(或更可能,代表)文件路径和名称,然后识别重命名? [英] How does Git record (or more likely, represent) file paths and names for its blobs, and then identify renames?

查看:110
本文介绍了Git如何为它的斑点记录(或更可能,代表)文件路径和名称,然后识别重命名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的头脑围绕git设法'记住'文件名及其路径的方式,因为它只存储blob中的文件内容。 Abizem是一个很好的解释吗?链接? (这是迄今为止我见过的最好的)



后续问题是git如何确定何时有相似性,特别是在移动'或路径名更新? (根据我的Q 子目录重命名)。我需要能够维护现有的工作流程,该工作流程使用路径重命名作为低级别个人VCS的一部分(对于大型版本,我们有一个很大的铁VCS,但没有用于每天/每小时使用)

解决方案 git 定义了四种对象(Commit,Tag,Tree,Blob)。每个对象在其内容的散列之后被标识。

与重命名有关的三个对象包括:


  1. blob:这对应于一个提交的文件,该对象的内容是原始文件的压缩内容。

  2. 树:这对应于一个目录列表,它包含文件名到其他对象(blob或树)的映射,并记录访问索引。
  3. commit:这包含提交消息,指向父提交(除了第一次提交)和树对象


所以当你重命名一个文件并提交它,则会创建一个新的树对象(如果该子对象位于子目录中,则该对象不止一个),并使用新的映射名称作为对象,但该对象是相同的。



然而,git不会跟踪重命名,它会尝试通过比较文件内容来重新发现它们。如果两个文件非常相似,但名称不同,则认为它是重命名文件。这可能很耗时,如果有很多文件,它可能会失败。



编辑:看看Git社区书,它有一个关于git如何存储信息的很好的解释


I'm trying to get my head around the way that git manages to 'remember' a file's name and its path, given that it only stores file content within a blob. Is the explanation in link here by Abizem a good one? (it's the best I've seen so far)

The follow up question, is how does (where) git then determine when we have similarity, especially after a 'move' or path-name update? (as per my Q sub-directory renames). I need to be able to maintain an existing workflow that uses path renames as part of low level personal VCS (we have a big iron VCS for big releases, but nothing for day to day / hour to hour use)

解决方案

git defines four kinds of objects (Commit, Tag, Tree, Blob). Each object is identified after the hash of its content.

The three objects that are involved with renaming are :

  1. blob: this correspond to a committed file, the content of the object is the compressed content of the original file

  2. tree: this correspond to a directory listing, it contains a mapping of filename to other objects (either blobs or trees) and also record the access rigths

  3. commit: this contains the commit message, a pointer to the parent commit(s) (except for the first commit), and to a tree object

So when you rename a file and commit it, a new tree object is created (well, and more than one if it is in a subdirectory) with a new mapping name to object, but the object is the same.

However, git does not track rename, it try to rediscover them by comparing file content. If two file are really similar, but have different names, it consider it is a rename. This can be time consuming, and if there are lots of file, it can fail.

Edit: Take a look to the Git Community Book, that has a really good explanation on how does git store information.

这篇关于Git如何为它的斑点记录(或更可能,代表)文件路径和名称,然后识别重命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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