- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我们可以使用 git ls-remote
命令来获取给定 git 仓库的提交列表,例如this discussion
对于具有大量提交/标签的 repo ,此命令花费了我们相当长的时间 - 我们正在为其寻找参数和/或任何其他限制返回行数的命令,例如只读取返回列表中的前 3 行。
我们怎样才能做到这一点?
附:
我的 google search和 our site search帮助不大。
最佳答案
git ls-remote
工作于 fetching the full list of refs from the remote and then filtering it locally :
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
{
...
transport = transport_get(remote, NULL);
if (uploadpack != NULL)
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
/* Get all refs from the remote */
ref = transport_get_remote_refs(transport);
if (transport_disconnect(transport))
return 1;
if (!dest && !quiet)
fprintf(stderr, "From %s\n", *remote->url);
/* Filter the list of all refs */
for ( ; ref; ref = ref->next) {
if (!check_ref_type(ref, flags))
continue;
if (!tail_match(pattern, ref->name))
continue;
if (show_symref_target && ref->symref)
printf("ref: %s\t%s\n", ref->symref, ref->name);
printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
status = 0; /* we found something */
}
return status;
}
更新
根据 this page, explaining git transfer protocols ,如果远程支持dumb协议(protocol),那么你可以直接获取远程refs/heads/branchname
文件(例如使用curl
)。
The Dumb Protocol
If you’re setting up a repository to be served read-only over HTTP, the dumb protocol is likely what will be used. This protocol is called “dumb” because it requires no Git-specific code on the server side during the transport process; the fetch process is a series of HTTP GET requests, where the client can assume the layout of the Git repository on the server.
...
否则,当使用智能协议(protocol)时,从远程发送的第一条数据总是所有远程引用的列表,即任何通过智能协议(protocol)连接到远程的 git 命令就像 git ls -remote
在内部运行(从技术上讲,所有此类命令都调用 transport_get_remote_refs()
函数)。不幸的是,在这种情况下,没有办法加快您的查询速度,甚至没有解决方法。
The Smart Protocol
...
Uploading Data
To upload data to a remote process, Git uses the
send-pack
andreceive-pack
processes. Thesend-pack
process runs on the client and connects to areceive-pack
process on the remote side....
The
git-receive-pack
command immediately responds with one line for each reference it currently has....
Downloading Data
When you download data, the
fetch-pack
andupload-pack
processes are involved. The client initiates afetch-pack
process that connects to anupload-pack
process on the remote side to negotiate what data will be transferred down....
After
fetch-pack
connects,upload-pack
sends back something like this: ... This is very similar to whatreceive-pack
responds with, but the capabilities are different (i.e. the list of all refs + some additional data)....
关于git - 'git ls-remote'命令参数限制返回的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45253392/
如果我执行 ls -la,我会得到如下结果 total 16 drwxr-xr-x 4 rockse staff 136 Apr 28 16:55 . drwx------+ 23 rocks
我找到了一些Linux文件,当我键入ls -lah时,它将输出以下权限格式: ... drwxr-xr-x. 2 root root ... -rw-rw-r--. 1 root r
我正在尝试从 python 执行 ls -l 来检查文件的最后修改日期。 os.listdir 不显示长列表格式。subprocess.call 显示格式,但实际上打印它,并返回 0。我希望能够将其放
以下 shell 函数定义卡在 Cygwin 的 bash 控制台 (RHEL/Ubuntu) 中,当它被调用时它只是退出终端。 $ function ls { ls; } $ ls 为什么会出现这种
为什么这两个命令的输出不同: ls | cat ls 第一个似乎用换行符分隔文件名。 这也适用于命令 suc 有 ls > outfile 和类似的东西。 我使用的是 Mac OSX,如果这有什么不同
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我使用 eshell-parse-command 'ls -l' 得到了这个: (progn (eshell-trap-errors (eshell-named-command "l
如何使用 RegExp 在 JavaScript 中实现类似于 alias 的功能? ALIAS = [{pattern: /^ls[$ ]/, replace: 'ls --color '}] s
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在编写一个 shell 程序,当将值传递给 execv() 时,我需要一个指向程序名称的 char 指针(即 ls),我需要一个指向参数的 char 指针数组的指针。 我会检查并解析用户的输入,如
我对使用 bash 编写脚本还比较陌生,并编写了以下脚本: # Set variables logfile=/tmp/peter/logfile.log indir=/mls/indir/IG/ te
所以基本上我有一个任务要使用 strace 进行分析,ls 命令需要哪些系统调用才能提供与 ls -l 相同的信息。 但是对于 ls -l 命令有许多奇怪的系统调用,例如 stat 64 被调用时使用
我在 ubuntu 的文件夹中有一个文件夹列表。IE。/mnt/source/customcode/files/brands/下 root@a919794ec280:/mnt/source/custo
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
#include #include #include #include #include int flag; void catch (int sig) { if (sig == SIGI
我使用 Process 来调用 shell(zsh),我想 cd ~ 或其他一些目录,例如在 shell 中定义的 cd $PROJ_ROOT。但似乎无法处理这些 token 。如何解决这个问题? s
我在我的 Centos5 机器上运行了这个: ls -al & ; ls -al 我期待它在后台运行 ls -al,同时在前台运行 ls -al,并演示终端的输出是如何被破坏的通过这样做。 但是,我得
当我在 PowerShell 中使用 Get-ChildItem 时,我会得到目录中以行格式设置的项目列表。该列表经常会超出屏幕,如果我想查看列表的其余部分或以前的命令和输出,则迫使我向上滚动。我想为
我试图用所有必要的参数绕过调用 JNIEnv->DefineClass 方法,但当我尝试从 java 调用该方法时,它总是返回 java.lang.NoClassDefFoundError: ls.H
我是一名优秀的程序员,十分优秀!