Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

How to get the sha of a single file in a remote git repo

I'd like to be able to check the sha/git id of a large file within a remote git repo. Is there a way to do that without downloading the file/checking out the repo?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need not download the file itself to find its hash ID, but you do have to have access to the remote repository to find the file's hash ID. This access needs to be above and beyond that required for a simple git clone: you need to be able to run git rev-parse or read a tree object from them.

If you cannot do this, your best bet is to obtain the file (or the entire commit).

Note that if you do get the file from the commit, you can save the commit hash ID that delivered that copy of the file. If, in the future, you have the same commit hash ID, it contains the same file. This is not as good as checking the file's hash ID directly, since a different commit could contain the same copy of the file, but it's generally easier since commit hash IDs are easier to obtain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...