You could leverage the <rev>:<path>
extended SHA-1 syntax to retrieve some meta data about the Blob from its parent Tree.
For instance, provided you work with the libgit2/libgit2sharp repository, and you'd like to retrieve the sha of the file Lib/MoQ/Moq.license.txt
from the master
branch:
- Leverage the GitHub Trees API to retrieve the content of the Tree matching the
Lib/MoQ
parent directory
- Retrieve from the returned Json payload the sha of the blob which path is
Moq.license.txt
- Make sure to url encode the the
<rev>:<path>
segment as it contains forward slashes
In brief:
The example link above will return the following payload
{
"sha": "2f2c87728225f9cbb6e2d8c5997b6031e72ddca4",
"url": "https://api.github.com/repos/libgit2/libgit2sharp/git/trees/2f2c87728225f9cbb6e2d8c5997b6031e72ddca4",
"tree": [
{
"path": "Moq.dll",
"mode": "100644",
"type": "blob",
"sha": "bdd4235f215541017a9f37b6155f18e309573838",
"size": 659968,
"url": "https://api.github.com/repos/libgit2/libgit2sharp/git/blobs/bdd4235f215541017a9f37b6155f18e309573838"
},
{
"path": "Moq.license.txt",
"mode": "100644",
"type": "blob",
"sha": "c9216ccba318292d76fd308f232e7871bbbe77be",
"size": 1748,
"url": "https://api.github.com/repos/libgit2/libgit2sharp/git/blobs/c9216ccba318292d76fd308f232e7871bbbe77be"
},
{
"path": "Moq.xml",
"mode": "100644",
"type": "blob",
"sha": "160c1b5165fd967f4c79bc6043f0cc2ec28710d8",
"size": 314572,
"url": "https://api.github.com/repos/libgit2/libgit2sharp/git/blobs/160c1b5165fd967f4c79bc6043f0cc2ec28710d8"
}
],
"truncated": false
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…