V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
thomaswang
V2EX  ›  问与答

求 git 的一个指令

  •  
  •   thomaswang · 2017-04-28 10:35:57 +08:00 · 1432 次点击
    这是一个创建于 2568 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我记得好像有一个指令可以对文件加密,得到 40 位 sha1 码,类似于:git sha1 a.txt 回车

    4 条回复    2017-04-29 01:59:51 +08:00
    shalk
        1
    shalk  
       2017-04-28 11:06:34 +08:00
    git hash-object
    thomaswang
        2
    thomaswang  
    OP
       2017-04-28 11:12:19 +08:00
    @shalk , 多谢了,我要给小伙伴们分享 Git 内部原理,需要这个
    thomaswang
        3
    thomaswang  
    OP
       2017-04-28 16:19:53 +08:00
    @shalk git hash-object 能计算出文件的 sha1 值,tree 和 commit 的 sha1 值是如何算出来的呢
    SoloCompany
        4
    SoloCompany  
       2017-04-29 01:59:51 +08:00   ❤️ 1
    tree object 可以用 git ls-tree | git mktree 重新计算出来
    但如果用 git hash-object -t tree 的话,需要二进制格式,恐怕不是这么容易构造出来

    commit object 的话,似乎没有什么好方法,好像也没有命令来构造二进制数据,虽然 git show <commit> — pretty=raw --no-patch 可以看到 commit 的完整内容,但没有命令可以把这个内容重新组装成一个 commit object
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   976 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:48 · PVG 04:48 · LAX 13:48 · JFK 16:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.