git在哪个文件中存储提交历史记录? [英] in which file git stores commit history?

查看:233
本文介绍了git在哪个文件中存储提交历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从git存储提交历史的文件中读取文件,以将每个提交信息存储在项目的DB中,并在项目视图中显示所有历史

I want to read from the file where git stores commit history to store each commit information in my project's DB and display all histories in my project view

推荐答案

没有可以查询的单个文件来获取提交历史记录.git的对象模型有很多很好的解释(例如计算机科学家的git Pro Git git社区本书),但在此处进行快速解释可能会很有用:

There's no single file you can interrogate to get the commit history. There are plenty of good explanations of git's object model (e.g. git for computer scientists, Pro Git, the git community book), but it might be useful to have a quick explanation here:

git中有多种类型的对象,最重要的是:

There are various types of objects in git, most importantly:

  • 斑点(文件)-只是二进制文件
  • (目录)-树是其他对象(通常是blob和树)的列表,其名称,哈希值和一组有限的权限
  • 提交(版本)-每个提交都包括其父提交,作者,提交消息和其他元数据的哈希值
  • blobs (files) - just binary files
  • trees (directories) - a tree is a list of other objects (usually blobs and trees) with their name, a hash and a limited set of permissions
  • commits (versions) - each commit includes the hashes of its parent commits, the author, the commit message and other metadata

每一个都由其内容的哈希标识,并且此哈希称为对象名称-这些是您在使用git的过程中可能见过的40位十六进制字符串.每个对象都作为松散对象(每个文件一个)或作为有效存储在pack文件中的许多对象之一存储在 .git/objects/目录中.文件 .git/HEAD 表示您的存储库当前所在的版本,通常包含对特定分支的引用,由 .git/refs/heads 或存储在打包文件中的参考.( HEAD 也可能直接指向特定提交的对象名称.)这些代表分支的文件之一,例如 .git/refs/heads/master ,仅包含一个对象名称.

Each of these is identified by a hash of its contents, and this hash is known as the object name - these are the 40 digit hex strings you've probably seen in the course of using git. Each object is stored in the .git/objects/ directory, either as a loose object (one per file) or as one of many objects stored efficiently in a pack file. The file .git/HEAD represents the version that your repository is currently at, and usually contains a reference to a particular branch, represented by a file under .git/refs/heads or a reference stored in pack file. (HEAD may also point directly to a particular commit's object name.) One of these files representing a branch, such as .git/refs/heads/master, just contains an object name.

为了从分支提示中遍历历史记录,git将在对象数据库中找到该文件中命名的对象,并递归地遵循指向其父对象的指针.

In order to traverse the history back from this branch tip, git will find the object named in that file in the object database, and recursively follow the pointers to its parents.

但是,对于您描述的用例(即遍历历史以将其导出),我强烈建议您执行以下操作之一:

However, for the use case you describe (i.e. traversing the history to export it), I would strongly suggest that you do one of the following:

  • 调用git命令以查找历史记录.如果您坚持使用所谓的"plumbing"命令,则它们的输出在git版本之间应该是稳定的.
  • 使用 libgit2 库查询存储库.libgit2是用于查询git存储库的完全可重入的库,该库现在具有对多种语言的绑定.
  • Invoke git commands to find the history. If you stick to using the so-called "plumbing" commands, their output should be stable across git versions.
  • Use the libgit2 library to interrogate the repository. libgit2 is a fully re-entrant library for interrogating git repositories, which now has bindings for many languages.

这篇关于git在哪个文件中存储提交历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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