【问题标题】:In what version of Git did git-status get the --branch option?git-status 在哪个版本的 Git 中获得了 --branch 选项?
【发布时间】:2011-12-16 02:04:12
【问题描述】:

在最新版本的 git 中,您可以使用标志 --branch(或 -b)来“以短格式显示分支和跟踪信息”。

git 什么时候(哪个版本)引入了这个选项?我知道至少在 1.7.0.4 中它不是一个选项。

【问题讨论】:

  • 为什么需要知道?
  • 这样我在 bash 脚本中使用的惰性 git 别名命令可以在具有多个 git 版本的多台计算机上工作。我有 'git status -b' 的 'gs' 别名,但如果 git 的版本太旧,它会引发错误。我想在我的 bash 文件中添加一个条件。哈基,我知道。

标签: git release


【解决方案1】:

git grep -Fgit log --oneline -S 的组合通常是从 Git 存储库中挖掘任何内容的强大方法:
manojldshis answer 中提出了一个单行代码,如果您像 OP 的问题一样搜索正确的评论,它应该可以在大多数情况下工作。去投票吧)。

VonC@NETVONC ~/Prog/git/git (master)
$ git grep -F 'Show the branch'
Documentation/git-status.txt:   Show the branch and tracking info even in short-format.

VonC@NETVONC ~/Prog/git/git (master)
$ git log --oneline --follow -S'Show the branch' -- Documentation/git-status.txt
46077fa Documentation+t5708: document and test status -s -b

VonC@NETVONC ~/Prog/git/git (master)
$ git tag --contains 46077fa
ko-maint
ko-master
ko-next
ko-pu
v1.7.2

所以 1.7.2

(我总是发现this thread git 挖掘的简洁插图)


注意:根据git describe,在1.7.1之后引入了233次commits:

VonC@NETVONC ~/Prog/git/git (master)
$ git describe 46077fa
v1.7.1-233-g46077fa

首次介绍于 2010 年 5 月 25 日星期二 16:52:03 +0200

VonC@NETVONC ~/Prog/git/git (master)
$ git show 46077fa

commit 46077fa5d477a3e96e0bb96042a2a9fdc9c818cb
Author: Michael J Gruber <git@drmicha.warpmail.net>
Date:   Tue May 25 16:52:03 2010 +0200

    Documentation+t5708: document and test status -s -b

    Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

【讨论】:

  • git grep 不需要-e,仅当模式以- 开头时才需要
  • @manojlds:谢谢(我已经更新了答案),并为您的答案 +1。我想说明组合 git grep + git log,但是,在这种情况下,您的回答更有效率。
【解决方案2】:

我通常会搜索字符串并在发行说明中查找它们(这样您就可以通过一个命令准确地知道它添加了哪个发行版):

这样的工作:

$ git grep -F "shows the current branch"
Documentation/RelNotes/1.7.2.txt: * "git status -s -b" shows the current branch

显然,它是在 1.7.2 中添加的。当然,你必须玩弄这些词,但你可以使用正则表达式来更容易地找到。

您可以使用 github 的高级搜索进行类似的搜索,这样您就不必克隆源代码。

你可以这样做:

repo:git/git path:Documentation/RelNotes/* <what you want to find>

在线搜索发行说明

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 2016-07-01
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多