thomaswang
V2EX  ›  问与答

求 git 的一个指令

  •  
  •   thomaswang · Apr 28, 2017 · 2153 views
    This topic created in 3494 days ago, the information mentioned may be changed or developed.

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

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

    commit object 的话,似乎没有什么好方法,好像也没有命令来构造二进制数据,虽然 git show <commit> — pretty=raw --no-patch 可以看到 commit 的完整内容,但没有命令可以把这个内容重新组装成一个 commit object
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2036 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 06:30 · PVG 14:30 · LAX 22:30 · JFK 01:30
    ♥ Do have faith in what you're doing.