当前位置: 首页 > news >正文

做微信首图的网站福州网站seo

做微信首图的网站,福州网站seo,网站联系我们怎么做,资海网络一年做多少网站文章目录 1. .git/objects 目录2. git cat-file 命令3. 根据文件内容生成 sha-14. 结语5. References 1. .git/objects 目录 git 是一个根据文件内容进行检索的系统。 当创建 hello.py, 填入 print("hello, world")的内容, 并执行 git add hello.py gi…

文章目录

    • 1. `.git/objects` 目录
    • 2. `git cat-file` 命令
    • 3. 根据文件内容生成 sha-1
    • 4. 结语
    • 5. References

1. .git/objects 目录

git 是一个根据文件内容进行检索的系统。 当创建 hello.py, 填入

print("hello, world")

的内容, 并执行

git add hello.py
git commit -m "init"

会在 .git/objects 目录生成子目录和文件。 子目录是2位,文件则是38位, 子目录和文件名字拼接起来的到的40位哈希码, 就是 SHA-1:

在这里插入图片描述
比较新版本的 git, 当执行上述 git 操作后, 会在 .git/objects 里存储多个子目录, 旧版本的 git 则只生成一个子目录。我用的 git 2.45.2, 目录结构为:

在这里插入图片描述

2. git cat-file 命令

git cat-file 命令能查看 sha-1 的情况, 这里暂时未查阅文档, 仅做基本介绍。

git cat-file -t <sha-1> 查看的是 sha-1 的类型。 其中 sha-1 是子目录和文件拼接起来的。例如

test git:(main)git cat-file -t 8cde7829c178ede96040e03f17c416d15bdacd01
blob

git cat-file -p <sha-1> 则是查看 blob 类型的内容:

test git:(main)git cat-file -p 8cde7829c178ede96040e03f17c416d15bdacd01
print("hello world")

3. 根据文件内容生成 sha-1

git 其实已经帮我们计算了 sha-1, 这是它存储文件时最基本的计算。 当我们有两个内容完全一样的文件被 git addgit commit, 对应的 blob 对象是相同的。

作为验证,我们拷贝 hello.py 内容并提交:

test git:(main)cp hello.py world.py
➜  test git:(main)git add world.py
➜  test git:(main)git commit -m "add world.py"
[main f72f05d] add world.py1 file changed, 1 insertion(+)create mode 100644 world.py

在这里插入图片描述
发现 .git/objects 目录新增的两个子目录,分别是 tree 和 commit 类型,并不是 blob 类型。 换言之, world.pyhello.py 对应的 blob 都是 8cde7829c17.

作为验证, 可以使用 Python 的 hashlib模块, 基于如下格式算出 sha-1:

blob {文件内容长度}\0 {file_content}

其中 {file_content} 是文件内容.

的到的结果是:

test git:(main) ✗ python githash.py hello.py
8cde7829c178ede96040e03f17c416d15bdacd01
➜  test git:(main) ✗ python githash.py world.py
8cde7829c178ede96040e03f17c416d15bdacd01

具体的 githash.py 实现如下:

#!/usr/bin/env python3from sys import argv
from hashlib import sha1
from io import StringIOclass Githash(object):def __init__(self):self.buf = StringIO()def update(self, data):self.buf.write(data)def hexdigest(self):data = self.buf.getvalue().encode('utf-8')h = sha1()h.update(f"blob {len(data)}\0".encode('utf-8'))h.update(data)return h.hexdigest()def githash_data(data):h = Githash()h.update(data)return h.hexdigest()def githash_fileobj(fileobj):return githash_data(fileobj.read())if __name__ == '__main__':for filename in argv[1:]:with open(filename, 'r', encoding='utf-8') as fileobj:print(githash_fileobj(fileobj))

4. 结语

.git/objects 目录存放的子目录中, 有些子目录是 blob 类型的对象, 表示了文件内容。 当两个文件内容一致时, git 对它们生成相同的 SHA-1。 在了解 blob 类型对象的 sha-1 计算过程的前提下,基于 Python 的 hashlib 写了一个工具, 能根据文件内容算出 sha-1, 这既可以作为理解 git 对象存储的初步, 也可以作为后续自行实现一个 mini-git 的基础。

5. References

  • https://gist.github.com/msabramo/763200
  • https://www.bilibili.com/video/BV1FZ4y1W7ZS/?p=2&spm_id_from=pageDriver
http://www.mnyf.cn/news/37718.html

相关文章:

  • 饿了吗网站做的比较好的地方电脑培训班在哪里有最近的
  • 设计网站 知乎sem是什么职业岗位
  • 云南百度小程序开发站长之家seo工具包
  • 网站建设的实验总结打开百度网站
  • 怎么看网站后台网页尺寸百度网站下载安装
  • 响应式网站需要单独的网址吗网络营销策划需要包括哪些内容
  • 有没有做请帖的网站seo关键词快速获得排名
  • 微商城设计网站建设注册网站流程
  • 免费搭建商城网站广告公司联系方式
  • 响应式网站模板html北京做网络优化的公司
  • 网上购物网站模板网络营销的策略包括
  • 上海到北京高铁票价多少赣州网站seo
  • 网页编辑与网站编辑百度信息流推广
  • 做国际网站有什么需要注意的视频外链工具
  • wordpress直接显示文章重庆网站关键词排名优化
  • 自定义菜单WordPress广州网站制作实力乐云seo
  • 建立官方网站多少钱seo黑帽优化
  • 成都网站建设的公司哪家好seo外链推广工具下载
  • 欧洲大带宽服务器seo站长工具下载
  • 临清住房建设网站加盟教育培训哪个好
  • 网站如何做信息表西安网站关键词优化推荐
  • 厦门建站服务seo优化需要多少钱
  • 网页传奇开服表seo新站如何快速排名
  • 怎么用asp做网站培训机构好还是学校好
  • 定手机网站建设猪八戒网接单平台
  • 资讯类响应式网站模板哪里有永久免费建站
  • wordpress域名二级目录如何跳转seo服务顾问
  • 毕设做网站工作量够吗搜索引擎优化师工资
  • 网站上怎么做图片变换动图个人网页
  • 淘客免费网站建设百度客服24小时人工电话