如何在git中获取索引的树形哈希? [英] How to get the tree hash of the index in git?

查看:130
本文介绍了如何在git中获取索引的树形哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git,我如何获得暂存更改的树形哈希?也就是说,如果我提交更改,提交的树哈希(不是提交哈希)将是什么?

With git, how can I get the tree hash of the staged changes? That is, what the tree hash of the commit (not the commit hash) would be if I committed the changes?

推荐答案

最简单的方法是提交树:

The easiest way is to commit the tree:

git commit-tree

说明

您不必完全提交,尽管当然也可以.您只需要提交将具有的快照.

幸运的是,git commit的工作方式是分几个阶段构建提交.一次,git commit是一个简单的shell脚本,它运行了其他一些更基本的Git命令: 1

Fortunately, the way git commit works is that it builds the commit in several stages. At one time, git commit was a simple shell script, that ran these other more-basic Git commands:1

  1. git write-tree:不带任何参数,并且,如果成功,则使用当前索引中的任何内容创建树对象,并将哈希ID打印到其标准输出.

  1. git write-tree: this takes no arguments, and—if it succeeds—makes a tree object from whatever is in the index right now, and prints the hash ID to its standard output.

git commit-tree:这需要几个参数(您选择的父哈希ID和一个树哈希ID一样多)和一个提交消息,并构建一个提交对象.提交的快照是您为其提供其哈希ID的树,该树来自步骤1.该命令将新提交对象的哈希ID打印到其标准输出.

git commit-tree: this takes several parameters (as many parent hash IDs as you choose, and one tree hash ID) and a commit message, and builds a commit object. The commit's snapshot is the tree whose hash ID you gave it, which comes from step 1. The command prints the hash ID of the new commit object to its standard output.

git update-ref:这将更新引用,例如分支名称.它至少需要两个参数:要更新的名称和新值(或指示删除名称"的标志).

git update-ref: this updates a reference, such as a branch name. It takes at least two arguments: the name to update, and the new value (or a flag to indicate "delete the name").

您要做的只是第一步.

1 git update-ref可能比commit shell脚本更新,因为在糟糕的过去,编写引用只是意味着使用适当的echo命令.符号HEAD ref只是一个符号链接.参考从未打包.一旦引用变得更高级并且需要锁定,git update-ref就变得很有必要.

1git update-ref might be newer than the commit shell script, since in the bad old days, writing a ref just meant using an appropriate echo command. The symbolic HEAD ref was just a symbolic link. References were never packed. Once references got fancier and needed locking, git update-ref became necessary.

这篇关于如何在git中获取索引的树形哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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