简体   繁体   English

github上传文件功能如何工作?

[英]How does github upload file feature works?

I came across a reddit post sometime back about how does github upload a file feature doesn't actually clone the project, instead it modifies the git history through low-level api.我在某个时候看到了一篇关于 github upload a file功能实际上并没有克隆项目的 reddit 帖子,而是通过低级 api 修改了 git 历史记录。 I'm unable to find that reddit post again :-(我再也找不到那个 reddit 帖子了:-(

I have a similar requirement to add & push a file to a git repo but cloning the entire repo is very costly (files are huge).我有一个类似的要求将文件添加和推送到 git 存储库,但克隆整个存储库的成本非常高(文件很大)。 Hence, I'm looking for low-level git api commands to use in order to add file to repository and push without cloning.因此,我正在寻找低级 git api 命令来使用,以便将文件添加到存储库并推送而不克隆。

FYI - Shallow cloning won't work for me, since all the large files are located in the project root.仅供参考 - 浅克隆对我不起作用,因为所有大文件都位于项目根目录中。

There are other similar questions, but have no solution - everybody says it's impossible.还有其他类似的问题,但没有解决方案 - 每个人都说这是不可能的。 Considering github did it, there should be a way.考虑到github做到了,应该有办法。

GitHub has the repository, so it's just a matter, on GitHub, of extracting the latest commit, writing the file, updating the index, and making a new commit. GitHub 拥有存储库,因此在 GitHub 上只需提取最新提交、写入文件、更新索引和进行新提交即可。 1 You can do the same thing on any server that has the entire repository: accept a file, check out the desired commit, add the file, and make the new commit. 1您可以在拥有整个存储库的任何服务器上执行相同的操作:接受文件、检出所需提交、添加文件并进行新提交。


1 In fact, all you really need to do is read the commit into an index file with git read-tree , write a blob object with git hash-object -w , then update the index in place and use git write-tree , git commit-tree , and git update-ref to insert the new commit. 1实际上,您真正需要做的就是使用git read-tree将提交读入索引文件,使用git hash-object -w写入 blob 对象,然后就地更新索引并使用git write-tree , git commit-treegit update-ref插入新的提交。 These plumbing commands do not require a separate work-tree directory.这些管道命令不需要单独的工作树目录。 It's easier if you have a work-tree directory, though, as that makes the user-interface commands work.但是,如果您有一个工作树目录会更容易,因为这会使用户界面命令起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM