106

我有以下问题:

  • master工作正常的版本
  • 之前的最后一个标签的版本master(比如last)有一个错误
  • 一位同事需要一个补丁来last修复那个特定的错误

好的。让我们向我们的朋友询问git bisect修复该错误的修订版:

git bisect start
git bisect bad last
git bisect good master

但这行不通:

一些好的转速不是坏转速的祖先。
git bisect 在这种情况下无法正常工作。
也许你误会了好转速和坏转速?

有什么提示可以克服这个吗?我错过了文档中的某些内容吗?

4

5 回答 5

114

从 git 2.7 开始,您可以使用参数 --term-old 和 --term-new。

例如,您可以这样识别问题修复提交:

git bisect start --term-new=fixed --term-old=unfixed
git bisect fixed master
git bisect unfixed $some-old-sha1

当你测试时,说git bisect fixedgit bisect unfixed酌情。

旧答案,适用于 2.7 之前的 git 版本

与其暂时训练自己认为坏就是好,好就是坏,为什么不创建一些别名呢?

添加~/.gitconfig以下内容:

[alias]
        bisect-fixed = bisect bad
        bisect-unfixed = bisect good

您可以开始识别问题修复提交:

$ git bisect start
$ git bisect-fixed master
$ git bisect-unfixed $some-old-sha1

当你测试时,说git bisect-fixedgit bisect-unfixed酌情。

于 2013-06-17T17:45:42.753 回答
48

我只会“欺骗” git 并交换好 <=> 坏的含义。

换句话说,将“坏”视为没有表现出问题的东西,因此这不是您的补丁所基于的“好”版本。

不管怎样,好与坏都是相当主观的概念,对吧?:)

git bisect start
git bisect good last
git bisect bad master
于 2013-03-14T10:53:00.157 回答
22

如果您git bisect run像我一直在使用 Perl 的prove命令(运行自动测试)一样使用,那么您就没有机会交换goodbad. 测试成功将报告为退出代码。

我找到了一个有效的 Bash 语法来否定程序运行的退出代码git bisect run

git bisect start
git bisect bad HEAD                 # last revision known to PASS the tests
git bisect good $LAST_FAIL_REVISION # last revision known to FAIL the tests
git bisect run bash -c "! prove"

这给了我第一个通过prove.

于 2016-03-22T14:54:13.403 回答
10

Git 现在允许您使用old并且new无需先定义它们。您必须在git bisect start没有提交的情况下调用作为进一步的参数,然后通过调用正确开始二分

git bisect old <rev>
git bisect new <rev>

https://git-scm.com/docs/git-bisect#_alternate_terms

这基本上是@MarcH 建议应该实施的。

于 2016-12-25T16:21:20.483 回答
6

Git 别名是个好主意,但是术语fixed和 与 和有unfixed相同的问题:你不能让它们与回归和进展兼容。很容易找到适用于任何一种方式的单词:只需从原始的二分搜索术语中挑选它们,该术语本质上是中性的,没有先入为主的好坏。例如:goodbad

git config --global alias.bisect-high 'bisect bad'
git config --global alias.bisect-low  'bisect good'

使用这样的中性术语,您始终可以输入:(git bisect-highgit bisect-upper,或git-bisect max,...您的选择!)无论您是在寻找回归还是修复

太糟糕了 git bisect 开发人员不能简单地重用任何现有的术语。一般来说,用户界面不是 git 关心的问题:http: //stevebennett.me/2012/02/24/10-things-i-hate-about-git/

于 2015-02-19T00:07:44.177 回答