Search code examples
githubgithub-pagesgithub-api

How do I find Github File_ID?


I have created a new repository on github and uploaded a test index.html file on it . How can I find the File_ID for this file ?

Should be something like : File_ID=765345_index.html

I was able to get User_ID via api at https://api.github.com/ but I have no idea what to do for File_ID .


Solution

  • GitHub does not assign a unique ID to each file in a repository like it does for users or commits. However, each file in a Git repository has a unique SHA hash that represents its content. You can use this SHA hash as a unique identifier for a file.

    You can retrieve the SHA hash of a file using the GitHub API. Here's an example of how you can do this using curl:

    curl -H "Accept: application/vnd.github.v3+json" \
    https://api.github.com/repos/{owner}/{repo}/contents/{path_to_file}
    

    Replace {owner}, {repo}, and {path_to_file} with your GitHub username, your repository name, and the path to your file, respectively.

    This will return a JSON response that includes a sha field. This is the SHA hash of your file.

    Note that the SHA hash will change whenever the content of the file changes. If you need a permanent, unchanging ID for a file, you might need to implement this yourself, as GitHub does not provide this feature.