有没有一种简单的方法来“git描述”?远程存储库?

发布于 12-14 14:12 字数 267 浏览 2 评论 0原文

我想在远程服务器上执行以下命令:

git archive --prefix="$tag/" --remote="ssh://$gitserver/var/git/$repo" "$tag" | tar -xvf-

问题是我不知道 $tag 是什么。它应该是最新克隆上 git describe --abbrev=0 的输出,但我不知道如何在不创建存储库的本地克隆的情况下获取该信息。是否可以在不进行本地克隆的情况下执行此操作?

I want to execute the following command on a remote server:

git archive --prefix="$tag/" --remote="ssh://$gitserver/var/git/$repo" "$tag" | tar -xvf-

The problem is I don't know what $tag is. It should be the output of git describe --abbrev=0 on an up-to-date clone, but I don't know how to get that information without making a local clone of the repository. Is it possible to do this without making a local clone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大海や2024-12-21 14:12:27
#!/usr/bin/awk -f
BEGIN {
  FS = "[ /^]+"
  while ("git ls-remote " ARGV[1] "| sort -Vk2" | getline) {
    if (!sha)
      sha = substr($0, 1, 7)
    tag = $3
  }
  while ("curl -s " ARGV[1] "/releases/tag/" tag | getline)
    if ($3 ~ "commits")
      com = $2
  printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha
}

样本输出

$ git-describe-remote.awk https://github.com/stedolan/jq
jq-1.4-148-g89791a0
#!/usr/bin/awk -f
BEGIN {
  FS = "[ /^]+"
  while ("git ls-remote " ARGV[1] "| sort -Vk2" | getline) {
    if (!sha)
      sha = substr($0, 1, 7)
    tag = $3
  }
  while ("curl -s " ARGV[1] "/releases/tag/" tag | getline)
    if ($3 ~ "commits")
      com = $2
  printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha
}

Sample output

$ git-describe-remote.awk https://github.com/stedolan/jq
jq-1.4-148-g89791a0
嘦怹2024-12-21 14:12:27

在不向本地磁盘添加太多内容的情况下开始解析标记的唯一方法是:

  • 创建一个空存储库,
  • 添加远程存储库的远程地址,
  • 尝试使用 git fetch - -dry-run

不过,这将加载远程存储库的包文件。
我认为您不能只查询此信息而不下载某些东西。

例如,我已经为 gitolite 存储库完成了此操作:

VonC@NETVONC /c/prog/git
$ git init g2
Initialized empty Git repository in c:/prog/git/g2/.git/

VonC@NETVONC /c/prog/git
$ cd g2

VonC@NETVONC /c/prog/git/g2 (master)
$ git remote add origin https://github.com/sitaramc/gitolite.git

VonC@NETVONC /c/prog/git/g2 (master)
$ git fetch --dry-run
remote: Counting objects: 5114, done.
remote: Compressing objects: 100% (1919/1919), done.
remote: Total 5114 (delta 3548), reused 4664 (delta 3142)
Receiving objects: 100% (5114/5114), 1.81 MiB | 722 KiB/s, done.
Resolving deltas: 100% (3548/3548), done.
From https://github.com/sitaramc/gitolite
 * [new branch]      bp-v2.0.3  -> origin/bp-v2.0.3
 * [new branch]      fedora-temp -> origin/fedora-temp
 * [new branch]      gh-pages   -> origin/gh-pages
 * [new branch]      master     -> origin/master
 * [new branch]      pu         -> origin/pu
 * [new branch]      temp-br--data-dumper-problem-demo -> origin/temp-br--data-dumper-problem-demo
 * [new branch]      vrs        -> origin/vrs
 * [new tag]         v2.1       -> v2.1
From https://github.com/sitaramc/gitolite
 * [new tag]         v0.50      -> v0.50
 * [new tag]         v0.55      -> v0.55
[...]
 * [new tag]         v2.0rc2    -> v2.0rc2
 * [new tag]         v2.1       -> v2.1
                                   ^^^^
                                    |
                                    --- could be the tag you need

如上所述,唯一的痕迹是包文件,因此至少在获得信息后您可以轻松清理它们:

VonC@NETVONC /c/prog/git/g2 (master)
$ l .git/objects/pack/
total 1000
drwxr-xr-x    4 VonC     Administ        0 Nov  8 19:45 ..
-r--r--r--    1 VonC     Administ  1898987 Nov  8 19:46 pack-c70771bc8a5ecc099ed88da0c3f631f84b34fe9d.pack
-r--r--r--    1 VonC     Administ   144264 Nov  8 19:46 pack-c70771bc8a5ecc099ed88da0c3f631f84b34fe9d.idx
drwxr-xr-x    2 VonC     Administ     4096 Nov  8 19:46 .

The only way you could start parsing for your tag, without adding too much to your local disk, would be:

  • make an empty repo
  • add the remote address of your remote repo
  • try a git fetch --dry-run

That will load the pack files of the remote repo, though.
I don't think you can just query this information without downloading something.

I have done it for a gitolite repo for instance:

VonC@NETVONC /c/prog/git
$ git init g2
Initialized empty Git repository in c:/prog/git/g2/.git/

VonC@NETVONC /c/prog/git
$ cd g2

VonC@NETVONC /c/prog/git/g2 (master)
$ git remote add origin https://github.com/sitaramc/gitolite.git

VonC@NETVONC /c/prog/git/g2 (master)
$ git fetch --dry-run
remote: Counting objects: 5114, done.
remote: Compressing objects: 100% (1919/1919), done.
remote: Total 5114 (delta 3548), reused 4664 (delta 3142)
Receiving objects: 100% (5114/5114), 1.81 MiB | 722 KiB/s, done.
Resolving deltas: 100% (3548/3548), done.
From https://github.com/sitaramc/gitolite
 * [new branch]      bp-v2.0.3  -> origin/bp-v2.0.3
 * [new branch]      fedora-temp -> origin/fedora-temp
 * [new branch]      gh-pages   -> origin/gh-pages
 * [new branch]      master     -> origin/master
 * [new branch]      pu         -> origin/pu
 * [new branch]      temp-br--data-dumper-problem-demo -> origin/temp-br--data-dumper-problem-demo
 * [new branch]      vrs        -> origin/vrs
 * [new tag]         v2.1       -> v2.1
From https://github.com/sitaramc/gitolite
 * [new tag]         v0.50      -> v0.50
 * [new tag]         v0.55      -> v0.55
[...]
 * [new tag]         v2.0rc2    -> v2.0rc2
 * [new tag]         v2.1       -> v2.1
                                   ^^^^
                                    |
                                    --- could be the tag you need

As mentioned above, the only traces are the pack files, so at least you can easily clean them once you have your information:

VonC@NETVONC /c/prog/git/g2 (master)
$ l .git/objects/pack/
total 1000
drwxr-xr-x    4 VonC     Administ        0 Nov  8 19:45 ..
-r--r--r--    1 VonC     Administ  1898987 Nov  8 19:46 pack-c70771bc8a5ecc099ed88da0c3f631f84b34fe9d.pack
-r--r--r--    1 VonC     Administ   144264 Nov  8 19:46 pack-c70771bc8a5ecc099ed88da0c3f631f84b34fe9d.idx
drwxr-xr-x    2 VonC     Administ     4096 Nov  8 19:46 .
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文