gpt4 book ai didi

git - git bisect 如何选择一个没有第一个好的提交作为祖先的提交? (使用 --first-parent)

转载 作者:行者123 更新时间:2023-12-03 19:06:09 25 4
gpt4 key购买 nike

我有一个使用“主干”流的存储库,其中包含 merge 和创建 merge 提交的功能分支,并且我正在使用 bisect 来尝试查找何时引入问题。问题识别过程涉及与已知良好提交的结果进行比较,因此我使用 git bisect --first-parent (2.29 中的新增功能)跳过不在“主干”分支中的提交(识别导致问题的 merge 提交对我来说就足够了)。
然而,git bisect --first-parent正在选择没有我作为祖先的第一个良好提交的提交,我不确定这怎么可能。
在下面的例子中,提交 2好和4不好。

  a 
/ \
1-2-3-4
--first-parent ,我希望功能分支提交 a包含在二等分中,但是使用 --first-parent ,我希望它跳过那个提交,只测试 merge 提交, 3 .
我已经在一个小型存储库上对此进行了测试,它的行为符合我的预期,但是我更大、更复杂的存储库并没有跳过没有 first-good 的提交。作为祖先,我正在努力理解为什么。
我的命令是
# both "first-good" and "first-bad" are tags on the "trunk" branch
git bisect start --first-parent
git merge-base --is-ancestor first-good first-bad # returns TRUE
git merge-base first-good first-bad # returns first-good
git checkout first-bad
git bisect bad
git checkout first-good
git bisect good
git merge-base --is-ancestor first-good HEAD # returns FALSE - why/how?
git merge-base first-good HEAD # returns some other commit - why/how?

最佳答案

在 git@47f0f94bc7 中,如果 first-good 提交仅作为 merge 提交的第二个父级存在于主线中,则会观察到问题中描述的行为。考虑到标志的名称,我想这在某种程度上是预料之中的,但是如果您依赖 first-good 提交进行工作构建,确实会导致令人困惑的行为,因为并非所有的二等分都将包含该提交。
例如:

  a - b - c   # "trunk2"
/ /
1 - 2 # "trunk1"

# 2 is the `first-good` commit
# c is the `first-bad` commit
git bisect --first-parent 将选择 a 作为要测试的提交,即使它不是第一个已知良好提交 2 的祖先。在这种情况下,它似乎回溯到 a ,这是第一个不是 first-good 祖先的提交。它不测试 1 ,因为它是 first-good 的祖先,因此可以假设它也很好。
在此示例中,带有或不带有 --first-parents 标志的行为是相同的。从 trunk2 开始并 merge 回 first-good 的其他分支将继续被跳过。
虽然我相当确定这是“正确”的行为,并且对于大多数用例,用户不会注意到差异,但手册页可以使用此行为的一些详细信息和/或在 ojit_code 提交仅存在时给出的警告作为第二个 parent 。
在我的情况下发生这种情况是因为我们在某个时候“重新中继”,其中提交同时进入两个分支。

关于git - git bisect 如何选择一个没有第一个好的提交作为祖先的提交? (使用 --first-parent),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63608729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com