简体   繁体   中英

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. I'm unable to find that reddit post again :-(

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). Hence, I'm looking for low-level git api commands to use in order to add file to repository and push without cloning.

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 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. 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 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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