python - 如何获取任何存储库文件的 sha 密钥
问题描述
我想单独访问任何存储库文件的 sha 密钥。
如你看到的。有一个文件结构,其中包括我用 gitpython 创建的 .git 目录。我可以获得用于表示所有文件的存储库 sha 密钥,如下所示;
from git import Repo
repo = Repo("graph/features")
master = repo.head.reference
print(master.commit.hexsha)
我的问题是我想为任何文件(如 file2.txt)生成 sha 密钥。有什么方法可以实现。对不起,我是使用 gitPython 的新手。
解决方案
然后读取文件
>>> import hashlib
>>> file_text = 'content'
>>> hashlib.sha256(file_text.encode()).hexdigest()
'ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73'
>>>
推荐阅读
- asp.net-core - 如何将包含excel文件的表单数据发送到asp.net core中的控制器
- python - 基于多个条件和多个值分配变量
- ios - 如何在 M1 MacBook Pro 上的 Xcode 项目中下载 pod
- java - AES的计数器模式的计数器是如何递增的?
- python - 如何在 Python 中使用 Pandas 解析列中特定范围的数值?
- apache-spark - 重用pyspark缓存并在for循环中不持久
- excel - 为 Excel VBA 创建常量库的理想方法是什么?
- python - 无法使用 for 循环为我的值迭代列表
- kubernetes - 带有 skaffold 的 k3s:无法拉出容器
- python - Python 无法解析 Json 文件并出现错误“引发 JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data"