英文:
Can I add files to GitHub directly from a URL without downloading them first?
问题
I'm looking to add files straight from the internet to my GitHub repo without downloading them first. Is that doable? Like, I want to grab a file from "www.example.com/file1" and put it right into GitHub without saving it on my computer first.
英文:
I'm looking to add files straight from the internet to my GitHub repo without downloading them first. Is that doable?
Like, I want to grab a file from "www.example.com/file1" and put it right into GitHub without saving it on my computer first.
答案1
得分: 1
GitHub没有提供一种仅从互联网上的任意位置检查文件的方式。首先,这不太安全,因为您无法确定URL在您检查它的时间和GitHub检索它的时间之间是否已更改。此外,通常下载文件并不是一个很大的负担。
然而,GitHub的API提供了一种创建或更新文件内容的方法。您可以编写一个程序,下载文件内容,根据您想要的规则进行验证,然后直接上传到GitHub,而无需将其保存到磁盘上。请注意,这仅适用于小文件,因为超过一定大小后,无法使用API。
如果文件很大(我认为超过10 MiB),那么您必须克隆存储库,使用Git添加文件,然后上传。如果要最小化克隆的工作量,可以使用浅克隆(git clone --depth=1
)。
英文:
GitHub doesn't offer a way to just check in files from arbitrary locations on the Internet. First of all, that's not very secure, since you don't know that the URL hasn't changed from the time you inspected it to the time that GitHub would have picked it up. In addition, downloading the file is typically not a very big burden.
However, GitHub's API does offer a way to create or update file contents. You could write a program that downloads the file content, verifies it according to whatever rules you want, and then uploads it directly to GitHub, all without saving it to disk. Note that this is only the case for small files, since beyond a certain size, the API can't be used.
If the file is large (I think bigger than 10 MiB), then you have to clone the repository, add it using Git, and then upload. If you want to minimize the amount of work to clone, you can use a shallow clone (git clone --depth=1
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论