git ls-remote --tags git://github.com/git/git.git
列出没有克隆的最新代码。 我需要一种能够直接从最新标签克隆的方法
答案 0 :(得分:0)
# 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
找到此解决方案here
答案 1 :(得分:0)
将此称为~/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.
...