为什么“git bisect”分支不知道? [英] Why isn't 'git bisect' branch aware?

查看:110
本文介绍了为什么“git bisect”分支不知道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个错误的来源,这是自从过去一天在一个长命的分支(将在稍后被发布)之后提出的,称为 feature-x 的错误。



有一个bug。我发现我从脚本中没有看到的行为,可能是在任何提交中引入的,直到现在,特别是因为主机的功能在feature-x中大量使用,但在主机本身上却不太重要。



要测试此行为,我必须运行我的脚本depend.pl。但是,当二分法跳过代码的一半时,我的脚本在Master上不存在,所以不可能测试。



我相信这是因为平分把你拉出来一个无头的状态,但在这种情况下,我真的想在这个其他历史/变更集的上下文中,而不是漂浮在以太。



在任何人跳到命中之前嗡嗡声,我们的团队喜欢在这些情况下合并分支机构,因为比喻适用于这种情况,而不是退役。



  git init 

echo' sub f {print $ _; }'> main.pl
git add。
git commit -a -minital commit

git branch feature-x
git checkout feature-x
echo'main :: f(1)' > dependent.pl
git add。
git commit -a -m在功能X上开始工作
git tag dev-1.0

git checkout master
echosub f {return 1;} >
echosub f {return 2;}>
echosub f {return 3;}> main.pl
git commit -a -msub f {return 3;}

git tag release-1.0

git checkout feature-x
git merge master

echo'print main :: f();'> dependent.pl
git commit -a -m更新调用f

所以现在你会得到一个这样的回购:

  o更新调用f(分支头feature-x)
o将分支主合并到feature-x
| \
| o sub f {return 3; }(TAG release-1.0)(分支主管主人)
| o sub f {return 2; }
| o sub f {return 1; }
o |在功能X上开始工作(TAG'dev-1.0')
\ |
o初始提交

所以我运行命令 git bisect start feature -x dev-1.0 期望我能够找到在depend.pl中打破了我的代码,我最终提交了'sub f {return 2}',而没有我的功能变化历史, x(即如果我运行 ls ,我所看到的只有main.pl和depend.pl缺少)。





我如何测试什么破坏了我目前的分支?

解决方案

这里的问题是git bisect 分支知道。当你告诉它依赖是好的,测试是坏的,并且其中一个变化之间是合并提交,它知道为了弄清问题在哪里引入,它将要看看提交a,b和c - 否则,所有这一切都可以告诉你,是否因为合并提交而被破坏。



这听起来像你我们期待测试commit b与其他分支的更改的组合,这是在任何提交中不存在的内容,而 git bisect 只能让你测试提交!为了测试该内容,您必须进行一系列的测试合并 - 检查b,合并依赖,让您测试,然后检查a或c,合并依赖,让您再次测试。你可以很容易地做一个$ code> git merge --no-commit dependent 一旦你在提交b,然后做 git reset --hard 在运行 git bisect good / bad 之前进行测试。



否则,如果我误解了,你希望它不会在合并的分支上测试任何提交,只测试合并提交本身(你不在乎a,b或c哪一个打破了它),只是告诉它合并的分支上的一切都是好的。更好的是,如果你知道a,b和c与它无关。那么你知道甚至没有测试它们是好的!



但是你不能指望的一件事是git完全忽略提交a,b和c 。它完全没有办法知道他们的变化是否与你的错误相关,而且他们的变化是你的好坏的贡献之间的区别。


I'm trying to find the source of a bug that's come up since a commit in the past day on a long lived branch (which will be released much much later) called feature-x.

There's a bug though. I find behavior that I don't expect from my script which might have been introduced in any of the commit's up till now, specifically because features of master are used heavily in feature-x, but less so on Master itself.

To test this behavior, I have to run my script, dependent.pl. But when bisect jumps half way down the code, my script doesn't exist on Master and so it's impossible to test.

I believe this is because bisect pulls you out into a headless state, but in this case I really want to be in the context of this other history/changeset, and not floating in the ether.

Before anyone jumps to hit the you're doing it wrong buzzer, our team likes merging branches in these situations as the metaphor works well for this situation, not rebase-ing.

I'll demo this by creating a sample repo:

git init

echo 'sub f { print $_; }' > main.pl
git add .
git commit -a -m "inital commit"

git branch feature-x
git checkout feature-x
echo 'main::f(1)' > dependent.pl
git add .
git commit -a -m "Starting work on feature X"
git tag dev-1.0

git checkout master
echo "sub f { return 1; }" > main.pl
git commit -a -m "sub f { return 1; }"
echo "sub f { return 2; }" > main.pl
git commit -a -m "sub f { return 2; }"
echo "sub f { return 3; }" > main.pl
git commit -a -m "sub f { return 3; }"

git tag release-1.0

git checkout feature-x
git merge master

echo 'print main::f();' > dependent.pl
git commit -a -m "Updating call to f"

So now you get a repo that looks like this:

o Updating call to f ( Head of branch 'feature-x' )
o Merge branch master onto feature-x
|\
| o sub f { return 3; } (TAG release-1.0) ( Head of branch 'master' )
| o sub f { return 2; }
| o sub f { return 1; }
o | Starting work on feature X ( TAG 'dev-1.0' )
 \|
  o initial commit

So I run the command git bisect start feature-x dev-1.0 expecting I'll be able to find what broke my code in dependent.pl, I end up on commit 'sub f { return 2 }' without my history of changes from feature-x (i.e. If I run ls, all I see is main.pl and dependent.pl is missing).

This puts me in an untestable state. I cannot know if the current commit broke my work or not, nor can I say that commits on master broke it, so I can't say this commit is good or bad.

How can I test what broke my current branch?

解决方案

The problem here is that git bisect is branch aware. When you tell it that "dependent" is good and "test" is bad, and one of the changes between there is a merge commit, it knows that in order to figure out where the problem was introduced, it's going to have to look at commits a, b, and c - otherwise, all it would be able to tell you is whether or not it's broken as of that merge commit.

It sounds like what you're expecting is to test the combination of commit b with the changes from the other branch, which is content which doesn't exist in any commit, and git bisect only lets you test commits! In order to test that content, you'd have to do a series of test merges - check out b, merge dependent, let you test, then check out a or c, merge dependent, let you test again. You can very easily do git merge --no-commit dependent once it's left you at commit b, then do git reset --hard when done with testing before running git bisect good/bad.

Otherwise, if I've misunderstood you expect it not to test any commits on the merged branch, and only test the merge commit itself (you don't care which of a, b, or c broke it), simply tell it that everything on the merged branch is good. Even better if you know that a, b, and c have nothing to do with it. Then you know without even testing that they're good!

But the one thing that you can't expect is for git to completely ignore commits a, b, and c. It has absolutely no way of knowing whether or not their changes are relevant to your "bug", and their changes are part of the difference between your good and bad commits.

这篇关于为什么“git bisect”分支不知道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆