Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a Github file 's SHA blob

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/

How do I find the SHA blob for the specific file? Supposed in my testrepo in the test account here, what is the SHA blob for the test.txt file?

https://github.com/testacc01/testrepo01

Thank you so much!

like image 857
Kiddo Avatar asked Nov 26 '13 02:11

Kiddo


People also ask

How do I find a file SHA in GitHub?

So, you can see what the SHA is in the "sha" field of the JSON response. Use that when you formulate your request to update the file with a new version. After you have successfully updated the file, the file will have a new SHA that you will need to request before it can be updated again.

What is SHA in GitHub?

When you make a commit to save your work, Git creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of the specific changes committed along with who made them and when. Commits usually contain a commit message which is a brief description of what changes were made.

What is a GitHub blob?

A Git blob (binary large object) is the object type used to store the contents of each file in a repository. The file's SHA-1 hash is computed and stored in the blob object. These endpoints allow you to read and write blob objects to your Git database on GitHub. Blobs leverage these custom media types.


1 Answers

The docs for updating a file specify that you will need to provide the SHA for the file you will be replacing. The easiest way would be to query github for that, too. For example:

> curl https://api.github.com/repos/testacc01/testrepo01/contents/test.txt {   "name": "test.txt",   "path": "test.txt",   "sha": "4f8a0fd8ab3537b85a64dcffa1487f4196164d78",   "size": 13,  … 

So, you can see what the SHA is in the "sha" field of the JSON response. Use that when you formulate your request to update the file with a new version. After you have successfully updated the file, the file will have a new SHA that you will need to request before it can be updated again. (Unless, I guess, your next update goes on a different branch.)

like image 77
user3033893 Avatar answered Sep 28 '22 00:09

user3033893