Creating Multiple Views of same Git repository

Posted by bain

I have one big linux repository on my pc with many branches (local and remote), of which i frequent three branches every now and then,

ubunut-gutsy, linus, bain(my personal branch).

Unfortunately this means that every time i do the branch switch the next kernel compile cycle compiles almost everything since the branches differ a lot and touch many core header requiring the massive recompile. Of course one solution which is inherent in git is that i create three repos with hardlinked blobs so that i can do whatever in each of the branches. But this scheme has a big flaw in it. I can't keep all three repos in sync automatically. e.g. if i pull-update linux-net branch in one repo. the same branch in other two still remains old. and i have to manually add all the updates (and if i am not care full at cloning time all the remote branches and the branch structure).

So i have brewed a solution and i call it repository 'views'

Any git repository is basically a collection of diffs that are hashed with a strong cryptographic function. These are called as blobs. All referencing withing git repository is done using these hashes. All the hashes depend on all its previous or parent hashes.

If you take a look at .git directory of a git tree, you can find two files that are of concern to us,

HEAD and index

The HEAD file contains basically a hash of the commit that is currently checked out. And index contains all the changes that are to be committed on next commit.These two files basically define the state of your working tree.

Now lets assume that your repo is ~/gitrepo/.git

and you have master, testing, release branches in it.

you have checked out master in ~/gitrepo

but now you have to test out a small change in testing but don't want to disturb master.

What you can do is add second view to this repository. by using following recipe

  1. Create a new directory ~/gitrepo_view2
  2. Create .git dirctory : mkdir ~/gitrepo_view2/.git
  3. Soft link following directories to .git
    1. ~/gitrepo/.git/branches -> ~/gitrepo_view2/.git/branches
    2. ~/gitrepo/.git/logs -> ~/gitrepo_view2/.git/logs
    3. ~/gitrepo/.git/branches -> ~/gitrepo_view2/.git/hooks
    4. ~/gitrepo/.git/branches -> ~/gitrepo_view2/.git/info
    5. ~/gitrepo/.git/branches -> ~/gitrepo_view2/.git/objects
    6. ~/gitrepo/.git/branches -> ~/gitrepo_view2/.git/refs
  4. And then just swith to that directory and do a git checkout

I am using this quite neatly, but have to emphasize that i make changes only to one view and check them in.... rest is more or less read only. there might be inconsistencies cropping in or brakages in some cases to views and commits, but the main tree in any case remains intact due to the robust nature of git.

 

 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.