0

I have got a repository at github and several branches. The whole repo is about 2 gigs. Before moving to git, I had an ant script that would checkout a folder from svn repository, build binary files and then commit back to the repository.

Unfortunately after switching to git, I can't find a simple way to do it. Every time my ant script runs, I want it to get a fresh copy of folder from remote branch and commit back to it after doing some work. I do not want to download whole repsitory ( 2 GB of Data ) everytime I run ant script.

Here is an example of how my ant script looked with SVN

With GIT workflow looks like

  • GIT INIT
  • GIT CLONE http://project.branch15 ( 2 GB )
  • MODIFY SOME STUFF in /subfolder/subfolder/subfolder
  • COMMIT branch 15
  • 1
    Have you considered storing binary files somewhere *other than* your source repository? – Greg Hewgill Oct 28 '11 at 01:43
  • Yes, splitting up files in different sub-repositories makes it really hard to revert back to a version as source files and build files would have different version numbers and maintained seperately. So you cant say revert back to version 13 ( for both source and binary files – freakyshaggy Oct 28 '11 at 03:16
  • 2
    Don't clone **every time**, do it once! extract dir from local repo – Lazy Badger Oct 28 '11 at 04:03

2 Answers2

2

This sounds like you have too much stuff in one repository. You should refactor it to use submodules. *If there is a folder than can live independent of their ancestors or siblings then it is a good candidate for a submodule.

Git submodules are themselves git repositories and thus can be clones, checked out, modified and pushed to independent of the parent repository.

You can also have a hierarchy of submodules. So in your example each subfolder could be a submodule. (but you should heed the above *).

Another advantage of this approach is that you can clone the main repo (which might be 2GB) and assuming it is made up of some submodules (say 10 of ~200MB) without taking up the full 2GB. Then you can run submodule checkouts for the repos that you do want.

Here is an example:

File structure

  /MainApp/           
       /Utils    200MB
       /Lib    
^        /OSX    200MB
^        /WIN32  200MB
^        /WIN64  200MB  
^        /NIX    200MB 
       /Source   150MB 
                 =====
                 1.15GB

If the ^ folders are each a submodule you could do the following

$ git clone MainApp
  # Downloads the 200MB for Utils and the 150MB for Source (plus git files)
$ cd MainApp
$ git submodule update /Lib/OSX
  # Downloads the 200MB OSX folder
Will
  • 8,102
  • 5
  • 30
  • 32
  • Seems like the only way to achieve what i was doing with SVN is to refactor existing structure ( as suggested in the previous answer ) which is bit of a pain. I have accepted your comment as an answer as you have provided a useful example. – freakyshaggy Oct 28 '11 at 03:50
0

You cannot do this, this is not how Git works. Clone the repository to your computer, make the change, stage & commit it and then push it back to the other repository.

If your project was on a service like GitHub which supports editing the files on the site, then you wouldn't need do any of that. Modifying the file on the site would be incredibly simple.

Have you considered splitting up that repository into many different sub-repositories rather than having such a large one?

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • There must be a way. I am interested in any hack I can do to make it work. Downloading 2 GB of unneeded data is not efficient at all. – freakyshaggy Oct 28 '11 at 01:43
  • Yes, splitting up files in different sub-repositories makes it really hard to revert back to a version as source files and build files would have different version numbers and maintained seperately. So you cant say revert back to version 13 ( for both source and binary files ) – freakyshaggy Oct 28 '11 at 01:50
  • Also it is pretty easy to revert with submodules too. You simply revert the parent repository and then do a git submodule update and it will revert its children. The version of the child submodules is stored in the main repository. – Will Oct 28 '11 at 11:09
  • @Will Can you please point me to a resource describing how to revert back a submodule and how version number is stored in the main repository? – freakyshaggy Oct 30 '11 at 21:04
  • The version numbers are sha numbers really and are stored in a file called .gitmodules at the root of the repo. A good resource would be http://book.git-scm.com/5_submodules.html and http://stackoverflow.com/questions/7882603/revert-a-git-submodule-pointer – Will Oct 31 '11 at 12:43