Is it possible to add a file to the git repository without checking it locally?

Purpose: add a new file to the remote git repository without checking all this locally.

Why: I am creating an application that will add files to a custom git repository. Some of these repositories will be hundreds of megabytes. Some will be affected very rarely. I want to avoid using terabytes of disk space to store large repositories that will not be often affected, and I do not want to bear the inevitable delay of checking a 200 megabyte repo (many binary files) to add a new new file to it and put it back to the beginning.

I assume that the default git client CANNOT do this, but I hope someone wrote something that can pass the remote repo (doesn't care which language) without checking it in place. Does Cloud9 IDE have something like this?

The application will have full access to user git repositories either through SSH, or some mechanism that GitHub uses for oAuthed applications to configure repositories.

+4
source share
5 answers

WARNING: THE NEXT ANSWER SHOULD NOT WORK WITH THE LATEST GIT VERSIONS

(I am open to suggestions on how to make this work with current versions of git.)

The answer, it turns out, is surprisingly simple and shows how amazing git is.

  • Create a new git repo.
  • Add and commit new files.
  • tell the new repo where the remote repo is (git remote incremental ...)
  • click on remote repo.

Notes. The remote repo must either be a result or have a receive.denyCurrentBranch method for β€œignore” or β€œwarn”

This is based on the assumption that the added files are NEW and will not conflict with any other file in the repo.

The existing contents of the remote repository does not matter as long as you can be sure that you are not going to conflict with anything.

PS Thanks to everyone who posted possible workarounds.

+2
source

Depending on the structure of your repository, you can use sparse checks to avoid downloading large files:

http://schacon.github.com/git/git-read-tree.html#_sparse_checkout

(more info in Checkout subdirectories in Git? )

+2
source

Git has several options for shallow cloning and a specific file path, partial cloning, but they are not pushed.

The trick here is to use the flag - lightweight when checking - in this case, you can click on a limited repository.

However, these solutions look strictly imperfect ... It seems more intuitive that if the application has programmatic access to the git repository, then you should be able to create or require the installation of a git project specific to your applications, which is empty.

+2
source

If you have access to the repository shell, you can create a quickly imported file (see the git fast-import man page for details of the file format) and run git fast-import inside the remote repository.

If you do not have access to the shell, the solution is much more hacky. You need to complete the following tasks to make changes to the remote repo:

  • create the contents of all files (= generate a hash of the new file and find the hashes of unchanged files [you get them from the current tree])
  • create tree
  • create commit
  • click new file contents, tree and commit remote repo
  • click branch branch to server

I would start with the hg-git extension, as I assume there is some kind of code that does something like this.

+2
source

How about a second lightweight repository with only the files you need to add, a script at their end can check both repositories and add your files. That the script can also remove consumable files from your new repo so that it is easy.

+1
source

Source: https://habr.com/ru/post/1387886/


All Articles