git ls-remote --tags git://github.com/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-*
的脚本。使用 git clone-latest-tXX
也会给你一个类似的命令:
clone-latest-tag。 - Tom Halecd /bin
。然后输入start .
以在资源管理器中打开/bin
目录(通常为C:\Program Files\Git\usr\bin
)。在此处插入脚本。 - Mir-Ismailisort -V
。 - undefinedREPO=https://github.com/namespace/repo.git && \
git clone $REPO --single-branch --branch \
$(git ls-remote --tags --refs $REPO | tail -n1 | cut -d/ -f3)
$(git ls-remote --tags --refs $REPO | tail -n1 | cut -d/ -f3)
将最新的标签作为变量获取。我已经尝试过几个repo,没有任何问题(当然,没有标签的repo会失败),但如果有改进的地方,请告诉我。
您可以添加任何内容,例如-c advice.detachedHead=false
以避免出现关于分离状态的长时间警告。
helix-editor/helix
。最新版本是22.08,它位于列表中间。 - sweenish--sort=taggerdate
就可以检出最新的标签。似乎所有按日期排序的键都需要对象数据,这意味着你不能只克隆最新的标签。对于我的目的来说,这仍然足够接近。 - sweenish# Clone repo
$ git clone <url>
# Go into repo folder
$ cd <reponame>
# Get new tags from the remote
$ git fetch --tags
# Get the latest tag name, assign it to a variable
$ latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
# Checkout the latest tag
$ git checkout $latestTag