KingofGamesYami
KingofGamesYami

Reputation: 345

Github API (V3) Contents sha key

I'm sorry if this is obvious, but I can't figure out what this key is!

{
  "type": "file",
  "encoding": "base64",
  "size": 5362,
  "name": "README.md",
  "path": "README.md",
  "content": "encoded content ...",
  "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", <<THIS KEY>>
  "url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
  "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
  "html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
  "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
  "_links": {
    "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
    "self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
    "html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
  }
}

I marked the key with <> to help.

https://developer.github.com/v3/repos/contents/#get-contents

Upvotes: 1

Views: 782

Answers (1)

Chris
Chris

Reputation: 136975

That's the hash for the given blob, which is how Git represents files internally. It's common knowledge that commits have hashes, but so do all other Git objects:

Git is a content-addressable filesystem. Great. What does that mean? It means that at the core of Git is a simple key-value data store. You can insert any kind of content into it, and it will give you back a key that you can use to retrieve the content again at any time.

Trees, commits, and tags are the other types of Git objects.

To generate the hash of a file manually you can use the hash-object plumbing command:

$ git hash-object README.md
3d21ec53a331a6f037a91c368710b99387d012c1

Any1 change to the file's content will change the hash, but it is not dependent on the file's name, or permissions.

1As with all cryptographic hashes, duplicate hashes are possible but extremely unlikely.

Upvotes: 3

Related Questions