How to find a Github file 's SHA blob

后端 未结 3 1273
囚心锁ツ
囚心锁ツ 2021-02-05 02:46

I\'m using this API to update a file on my repo, it requires me to have a valid SHA blob for a file that I want to update:

http://developer.github.com/v3/repos/contents/

3条回答
  •  鱼传尺愫
    2021-02-05 03:21

    If you don't want to hit the api, you could generate the SHA yourself. Git generates the SHA by concatenating a header in the form of blob {content.length} {null byte} and the contents of your file. For example:

    content = "what is up, doc?"
    header = "blob #{content.bytesize}\0"
    combined = header + content # will be "blob 16\u0000what is up, doc?"
    sha1 = Digest::SHA1.hexdigest(combined)
    

    Source: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

提交回复
热议问题