git repository browsing

2019-06-04 03:43发布

问题:

I am interested if I can do repository browsing with git in the following way:

given a remote repository -fetch only data about the directory structure of a certain revision at the beginning - fetch files individually on choice given the knowledge acquired previously

for example(fake commands only to illustrate intent):

git clone --dont_get_me_repo_contents_please // the info about the file contents is somewhere and i see my/cool/file alongside with others git get my/cool/file

Supposedly I would not be owning that server (the one were the remote repo is stored). I can only interact with it through the git client.

I just want to use as little network transfer as possible and as little space.

Basically, what you do on github, when you look through the files of a revision, and you see the dirs, you click on a file and you get just those contents. The only info that gets sent over the network is the dir structure and the contents of the file you are looking at. I'm assuming it is interacting with the git repo on the server. now how does it do that?

I do not want something that does this, maybe just as an example,I want to know how this is done.

I've done some reading and I feel the answer is no, this cannot be done in this form. Is it the case that one cannot do this and one needs a checked out revision somewhere? If so, what are my best alternatives, given my objectives (use as little network traffic as possible, secondary - try to minimize space as well).

I'm sorry if my use of git terms is abusive (n00b here). I hope I got the idea across.

EDIT: What about MERCURIAL? can these things be done with it?

Thanks.

回答1:

You could start with a shallow git clone (say, only 1 revision in the history):

git clone --depth 1