Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browse and display files in a git repo without cloning

Tags:

git

Is there a way to browse and display files in a git repo without cloning it first? I can do those in svn using the commands:

svn ls /path/to/repo 
svn cat /path/to/repo/file-in-repo

I can supposedly use git show but doing:

git show /path/to/repo
git show HEAD:/path/to/repo

result to

fatal: Not a git repository
like image 640
Christian Alis Avatar asked Oct 06 '22 08:10

Christian Alis


People also ask

How do I see files in a git repository?

The Git Show command allows us to view files as they existed in a previous state. The version can be a commit ID, tag, or even a branch name. The file must be the path to a file. For example, the following would output a contents of a file named internal/example/module.go file from a tagged commit called “release-23”.

How do you display a hidden file in git?

Use the terminal to display the . git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files. If you pass it the -a flag, it will display hidden files.


2 Answers

The command you want is git ls-remote which allows you to get some information about remote repositories, but you cant show history or list directories or anything of that level: essentially it only lets you see the remote objects at a very high-level (you can see the current HEADs and tags for example).

The only real way to do what you want (if I understand correctly) would be to use ssh to run a remote command and return the results, for example:

ssh me@otherhost "cd repo && git log -n 10"

What you want would be lovely functionality if they could add it, but from what I read it's not very easy since getting history etc needs a lot of information to be local to git, and at that point you may as well have done a git fetch.

like image 193
jkp Avatar answered Oct 16 '22 00:10

jkp


Git is distributed version control system, while Subversion is centralized (client-server) version control system. They work differently; get used to that. Please read my answer explaining the consequences of that difference to git equivalent of svn status -u question at StackOverflow.

Repeating myself a bit: in centralized version control system (like CVS or Subversion) almost all commands are processed on server, and involve network. Very few commands are performed locally. Note that to have good performance of "svn status" and "svn diff" Subversion stores 'pristine copy' of checked-out version on client, to not have to involve network transfer for those common operations (this means that Subversion checkout = 2 x size of working directory at least).

In distributed version control system (like Git, Mercurial or Bazaar), where you have local copy (clone) of a whole repository, almost all commands are performed on client. Very few commands require network connection to other repository (to server).

The number of command you can perform on server is limited.

  • You can list all references on remote with "git ls-remote <URL>".
  • You can get snapshot of (part) of repository (if remote server enabled it) with
    "git archive --remote=<URL> HEAD".
  • You can clone only a few last commits (so called "shallow clone") with
    "git clone --depth=1 <URL>".
  • If server provides git web interface to repository, you can use it to browse.
like image 29
Jakub Narębski Avatar answered Oct 16 '22 01:10

Jakub Narębski