Git - 查找索引中单个文件的SHA1 [英] Git - finding the SHA1 of an individual file in the index

查看:171
本文介绍了Git - 查找索引中单个文件的SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  git add myfile.java 

如何找出此文件的SHA1?

解决方案

您希望 -s 选项 git ls-files 。这给你索引中文件的模式和sha1散列。

  git ls-files -s myfile.java 

请注意,您不希望 git hash-object 因为这会为您提供当前工作树中文件的sha1标识,而不是您添加到索引中的文件的标识。一旦您在 git add 之后更改了工作树副本,这些将会有所不同。


I've added a file to the 'index' with:

git add myfile.java

How do I find out the SHA1 of this file?

解决方案

You want the -s option to git ls-files. This gives you the mode and sha1 hash of the file in the index.

git ls-files -s myfile.java

Note that you do not want git hash-object as this gives you the sha1 id of the file in the working tree as it currently is, not of the file that you've added to the index. These will be different once you make changes to the working tree copy after the git add.

这篇关于Git - 查找索引中单个文件的SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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