如何获取 Git 的最新稳定版本号?

发布于 2024-09-03 12:05:33 字数 847 浏览 2 评论 0原文

我正在编写 git-install.sh 脚本: http://gist.github.com/419201

要获取 Git 的最新稳定版本号,我这样做:

LSR_NUM=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p')

2 个问题:

  1. 重构我的代码:是否有更好的方法以编程方式执行此操作?

  2. 这现在可以工作,但是很脆弱:如果 网页位于 http://git-scm.com/ 更改,上面的行可能会停止 工作。

    PHP 有一个可靠的 URL 来获取 最新发布版本: 有吗一个只输出php和mysql最新稳定版本号的网站?

    有没有类似的东西 吉特?这很接近: http://www.kernel.org/pub/software/scm /git/

I'm writing a git-install.sh script:
http://gist.github.com/419201

To get Git's latest stable release version number, I do:

LSR_NUM=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p')

2 Questions:

  1. Refactor my code: Is there a better way programmatically to do this?

  2. This works now, but it's brittle: if
    the web page at http://git-scm.com/
    changes, the line above may stop
    working.

    PHP has a reliable URL for getting
    the latest release version:
    Is there a site which simply outputs the latest stable version numbers of php and mysql?

    Is there something like this for
    Git? This comes close: http://www.kernel.org/pub/software/scm/git/

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

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

发布评论

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

评论(5

小傻瓜 2024-09-10 12:05:33

我只是这样做:

git ls-remote --tags git://git.kernel.org/pub/scm/git/git.git | ...

公共存储库的位置几乎可以保证保持固定,所以我不会真正认为它是脆弱的。 git-ls-remote 的输出也绝对不会改变。

版本号应该是最后一个标签;你可以用这样的东西来抓住它:

git ls-remote ... | tail -n 1 | sed 's@.*refs/tags/\(.*\)\^{}@\1@'

I'd just do this:

git ls-remote --tags git://git.kernel.org/pub/scm/git/git.git | ...

The location of the public repository is pretty much guaranteed to stay fixed, so I wouldn't really consider it brittle. The output of git-ls-remote will pretty definitely not change either.

The version number should be the last tag; you could grab it with something like this:

git ls-remote ... | tail -n 1 | sed 's@.*refs/tags/\(.*\)\^{}@\1@'
删除→记忆 2024-09-10 12:05:33

我使用 git-scm.com 来实现此目的。

latest_git_version=$(curl -s http://git-scm.com/ | grep "class='version'" | perl -pe 's/.*?([0-9\.]+)<.*/$1/')
echo $latest_git_version 

当你使用新机器并想要安装最新的稳定 git 时非常有用,如下所示:

cd /tmp
wget http://git-core.googlecode.com/files/git-${latest_git_version}.tar.gz
tar xzf git-${latest_git_version}.tar.gz
cd git-${latest_git_version}
./configure && make && sudo make install

也许这也是 kernel.org 的一个很好的后备方案,反之亦然。

I use git-scm.com for this.

latest_git_version=$(curl -s http://git-scm.com/ | grep "class='version'" | perl -pe 's/.*?([0-9\.]+)<.*/$1/')
echo $latest_git_version 

Very useful when you are on a new box and want to install latest stable git like so:

cd /tmp
wget http://git-core.googlecode.com/files/git-${latest_git_version}.tar.gz
tar xzf git-${latest_git_version}.tar.gz
cd git-${latest_git_version}
./configure && make && sudo make install

Maybe this would also be a good fallback for kernel.org or vice versa.

赢得她心 2024-09-10 12:05:33

我在 freebsd/bash 上使用这个:

git ls-remote --tags https://github.com/user/testpro.git |尾-n 1 | sed 's/.*refs\/tags\///g'

I am using this on freebsd/bash:

git ls-remote --tags https://github.com/user/testpro.git | tail -n 1 | sed 's/.*refs\/tags\///g'

2024-09-10 12:05:33

我通常只使用 maint 分支。它只获取在其他分支(如 pu 或 next)中经过严格测试的提交。它通常非常稳定,并且在任何给定时间实际上可能比最新的官方版本包含更少的错误。

I generally just use the maint branch. It only gets commits that have been rigorously tested in other branches like pu or next. It is generally very stable and at any given time is actually likely to contain less bugs than the latest official release.

拒绝两难 2024-09-10 12:05:33

我使用 github.com 并删除“-rc”版本,因为 kernel.org 响应不稳定。

卷曲 -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -P "/git/git/releases/tag/v\d" | grep -v rc | grep -v rc | grep -v rc | awk -F'[v\"]' '{print $3}' | head -1

如果你想在 bash 中检查结果;

GIT_INSTALL=$(curl -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -v rc  |  awk -F'[v\"]' '{print $3}' | head -1)

if [[ "$GIT_INSTALL" =~ ^[0-9]*?\.[0-9]*?\.[0-9] ]]
then
  echo GIT_INSTALL=$GIT_INSTALL
else
  echo "Failed to get the latest stable git version. Quit." 
  exit
fi

I use github.com and remove "-rc" versions due to kernel.org reponses unstably.

curl -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -v rc | awk -F'[v\"]' '{print $3}' | head -1

If you'd like to check the result in bash;

GIT_INSTALL=$(curl -s https://github.com/git/git/tags | grep -P "/git/git/releases/tag/v\d" | grep -v rc  |  awk -F'[v\"]' '{print $3}' | head -1)

if [[ "$GIT_INSTALL" =~ ^[0-9]*?\.[0-9]*?\.[0-9] ]]
then
  echo GIT_INSTALL=$GIT_INSTALL
else
  echo "Failed to get the latest stable git version. Quit." 
  exit
fi
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文