无需克隆即可浏览和显示 git 存储库中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1178389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:47:14  来源:igfitidea点击:

Browse and display files in a git repo without cloning

git

提问by Christian Alis

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:

有没有办法在 git repo 中浏览和显示文件而不先克隆它?我可以使用以下命令在 svn 中执行这些操作:

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

I can supposedly use git show but doing:

我应该可以使用 git show 但这样做:

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

result to

结果到

fatal: Not a git repository

采纳答案by jkp

The command you want is git ls-remotewhich 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).

您想要的命令是git ls-remote它允许您获取有关远程存储库的一些信息,但您不能显示历史记录或列出目录或该级别的任何内容:本质上它只能让您在非常高的级别查看远程对象(您可以看到例如当前的 HEAD 和标签)。

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 运行远程命令并返回结果,例如:

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.

如果他们可以添加它,您想要的将是可爱的功能,但从我读到的内容来看,这并不是很容易,因为获取历史记录等需要大量信息才能在 git 本地化,此时您可能已经完成了 git fetch .

回答by Jakub Nar?bski

Git is distributedversion 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 -uquestion at StackOverflow.

Git 是分布式版本控制系统,而 Subversion 是集中式(客户端-服务器)版本控制系统。它们的工作方式不同;习惯了。请阅读我的回答,解释这种差异对StackOverflow上的git 等效svn status -u问题的后果。

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).

再说一遍:在集中式版本控制系统(如 CVS 或 Subversion)中,几乎所有命令都在服务器上处理,并且涉及网络。很少有命令在本地执行。请注意,要获得“svn status”和“svn diff”的良好性能,Subversion 会在客户端存储检出版本的“原始副本”,而不必涉及这些常见操作的网络传输(这意味着 Subversion checkout = 2 x至少工作目录的大小)。

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).

在分布式版本控制系统(如 Git、Mercurial 或 Bazaar)中,您拥有整个存储库的本地副本(克隆),几乎所有命令都在客户端上执行。很少有命令需要到其他存储库(到服务器)的网络连接。

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.
  • 您可以使用“ git ls-remote<URL>”列出远程上的所有引用。
  • 您可以使用
    git archive--remote=<URL> HEAD”获取存储库(如果远程服务器启用它)的(部分)快照。
  • 您只能使用
    git clone--depth=1 <URL>”克隆最后的几个提交(所谓的“浅克隆”)。
  • 如果服务器提供 git web 接口到存储库,您可以使用它来浏览。

回答by Jerome Baum

Take a look at http://git-scm.com/book/en/Git-Internals-Transfer-Protocolsfor info on how to do this over some transport protocols. Note this won't work for standard git over SSH.

查看http://git-scm.com/book/en/Git-Internals-Transfer-Protocols以获取有关如何通过某些传输协议执行此操作的信息。请注意,这不适用于 SSH 上的标准 git。

For git over SSH, an up-to-date server-side git should allow you to git-archive directly from the remote, which you could then e.g. pipe to "tar t" to get a list of all files in a given commit.

对于 SSH 上的 git,最新的服务器端 git 应该允许您直接从远程进行 git-archive,然后您可以例如通过管道连接到“tar t”以获取给定提交中所有文件的列表。

回答by fela

GitHub is svn compatible so you can use svn ls

GitHub 与 svn 兼容,因此您可以使用 svn ls

svn ls https://github.com/user/repository.git/branches/master/

BitBucket supports git archive so you can download tar archive and list archived files. It is not very efficient but works:

BitBucket 支持 git 存档,因此您可以下载 tar 存档并列出存档文件。它不是很有效,但有效:

git archive [email protected]:repository HEAD directory | tar -t

回答by Anurag Kanungo

Not the exact, but a way around.

不是确切的,而是一种方法。

Use GitHub Developer API

使用 GitHub 开发者 API

  1. Opening this will get you the recent commits.

    https://api.github.com/repos/learningequality/ka-lite/commits

    You can get the specific commit details by attaching the commit hash in the end of above url.

  2. All the files ( You need sha for the main tree)

    https://api.github.com/repos/learningequality/ka-lite/git/trees/7b698a988683b161bdcd48a949b01e2b336b4c01

  1. 打开它会得到你最近的提交。

    https://api.github.com/repos/learningequality/ka-lite/commits

    您可以通过在上述 url 的末尾附加提交哈希来获取特定的提交详细信息。

  2. 所有文件(主树需要 sha)

    https://api.github.com/repos/learningequality/ka-lite/git/trees/7b698a988683b161bdcd48a949b01e2b336b4c01

I hope this may help.

我希望这可能会有所帮助。

回答by Anne van Rossum

This is probably considered dirty by some, but a very practical solution in case of github repositories is just to make a script, e.g. "git-ls":

有些人可能认为这很脏,但是在 github 存储库的情况下,一个非常实用的解决方案就是制作一个脚本,例如“git-ls”:

#!/bin/sh
remote_url=${1:? "
git-ls https://github.com/mrquincle/aim-bzr
git-ls https://github.com/mrquincle/aim-bzr/tree/master/aim_modules
requires URL as argument"} curl -s $remote_url | grep js-directory-link | sed "s/.* title=\"\(.*\)\".*//"

Make it executable and reachable of course: chmod a+x git-ls; sudo cp git-ls /usr/local/bin. Now, you just run it as you wish:

当然,让它可执行和可达:chmod a+x git-ls; sudo cp git-ls /usr/local/bin. 现在,您只需按照自己的意愿运行它:

git ls-tree -r <remote_branch> --name-only

Also know that there is a git instawebutility for your local files. To have the ability to show files and have a server like that does in my opinion not destroy any of the inherent decentralized characteristics of git.

还知道git instaweb您的本地文件有一个实用程序。在我看来,能够显示文件并拥有这样的服务器并不会破坏 git 的任何固有的分散特性。

回答by LinconFive

if you know the remote branch you want to check, you can find out the latest via:

如果您知道要检查的远程分支,可以通过以下方式找到最新的:

##代码##