简体   繁体   English

如何更改提交中的代码以帮助查找错误?

[英]How can I change code within a commit to help find a bug?

I am trying to track down a specific bug in my code, but the trouble is the bug appeared somewhere in a block of commits where the only way to check if the commit breaks is commented out, so I can't see which commit it is. 我试图找到我的代码中的特定错误,但问题是错误出现在提交块中的某处,检查提交中断是否被注释掉的唯一方法,所以我无法看到它是哪个提交。

I need to change one line of code, and have that line merge into several commits, can this be done? 我需要更改一行代码,并将该行合并到多个提交中,这可以完成吗?

The best way to find the first (or last) commit with a certain behaviour in a block of commits is to use git bisect . 在提交块中找到具有特定行为的第一个(或最后一个)提交的最佳方法是使用git bisect More specifically: git bisect run . 更具体地说: git bisect run

To automate the entire process you need to write a script which comments out the one line in question and then starts a test. 要自动执行整个过程,您需要编写一个脚本,该脚本会注释掉一行,然后开始测试。 the script should exit with code 0 if the code is good and code 1 if the code is bad. 如果代码是好的,脚本应该以代码0退出,如果代码是坏的,则代码1。

For an example read here: http://www.metaltoad.com/blog/mechanizing-git-bisect-bug-hunting-lazy . 有关示例,请阅读: http//www.metaltoad.com/blog/mechanizing-git-bisect-bug-hunting-lazy

也许你只需要使用git bisect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM