git - 如何在 Git 存储库中克隆最新标签

标签 git

git ls-remote --tags git://github.com/git/git.git

列出最新的标签而不克隆。
我需要一种能够直接从最新标签克隆的方法

最佳答案

调用 ~/bin/git-clone-latest-tag :

#!/bin/bash

set -euo pipefail
basename=${0##*/}

if [[ $# -lt 1 ]]; then
    printf '%s: Clone the latest tag on remote.\n' "$basename" >&2
    printf 'Usage: %s [other args] <remote>\n' "$basename" >&2
    exit 1
fi

remote=${*: -1} # Get last argument

echo "Getting list of tags from: $remote"

tag=$(git ls-remote --tags --exit-code --refs "$remote" \
  | sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g' | tail -n1)

echo "Selected tag: $tag"

# Clone as shallowly as possible. Remote is the last argument.
git clone --branch "$tag" --depth 1 --shallow-submodules --recurse-submodules "$@"

然后你可以这样做:
% git clone-latest-tag https://github.com/python/cpython.git
Getting list of tags from: https://github.com/python/cpython.git
Selected tag: v3.8.0b1
Cloning into 'cpython'...
remote: Enumerating objects: 4346, done.
...

关于git - 如何在 Git 存储库中克隆最新标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29780641/

相关文章:

git - Web 开发问题的基本版本控制 - 单个开发人员。 (SVN/GIT)

git - 单独团队项目中的 TFS 子模块

git - 在 git merge 期间,如何查看正在 merge 的提交

git - 如何防止 Gitlab 在分支 merge 时创建额外的 merge 提交

git - 推送到 +master 与强制推送

git - 将文件恢复到以前的版本后,git diff 显示没有差异?

r - 使用 RStudio 的 Git 工具时的错误

macos - Git 停止提示输入密码

git - 将整个分支重置/恢复到另一个分支状态?

使用 groovy 脚本在 Jenkins 中选择 Git 分支