[Practical Git] Diagnose which commit broke something with git bisect

Sometimes you find a bug in your project that has been around for a while without being noticed; it can be hard to track down where that bug was introduced and why just by searching through logs and diffs. Git has a slick tool called git bisect that can be used to find out which commit introduced problem in our code - it creates a binary search where the programmer can mark each search commit as good or bad; by the end of the bisect, Git shows you exactly which commit introduced the issue. In this lesson, we walk through an example of using git bisect from start to finish.

To get started:

git bisect start

First, we need to find out which commit cause the problem, now assume it is the lastest commit, so we need to mark it as ‘bad‘:

git bisect bad

Then , we need to find out which commit works fine, then mark it as good:

git log --oneline // to pick one which you are sure code works fine

# Then get the commit id

git bisect good <commit_id>

Then git will show you the commits which stay between the bad and good commits and will automatically checkout the next commit. Then you can do the testing and find out whether this commit is bad or not, if it is bad then mark as ‘bad‘ or the other way around.

Finnally git bisect will find out the bad commit which introduce the bugs, but we are still in the bisecting state, to back to normal, we need to run:

git bisect reset
时间: 2024-10-13 09:53:12

[Practical Git] Diagnose which commit broke something with git bisect的相关文章

Git工程开发实践(六)——Git工程实践扩展

Git工程开发实践(六)--Git工程实践扩展 一.Git提交日志规范 1.Git提交日志模板 Git支持对每次提交的日志信息进行规范,可以通过设置提交模板实现.建立一个gitCommitTemplate文件,内容为: #commit message包含三部分,header, body和footer,其中header必选,body和footer可选. # type(<scope>): <subject> #<body> #<footer> #type字段包含

第二章-第二题(练习使用git的add/commit/push/pull/fetch/clone等基本命令)--梁绍楠

题目描述: 每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 使用步骤: (1)创建版本库 选择一个合适的地方,创建一个空目录HelloWorld.而后通过git init把这个目录变成Git可以管理的仓库(目录下会多出了一个.git目录,该目录是git跟踪管理版本库的,勿轻易修改): 编辑hello文件,内容如下: (2)将文件hello放到git仓库 首先,需要设置用户名.邮箱信息

git for c#, commit本地,push服务器

//ok private static void push() { string wkDir = @"E:\DotNet2010\单位工程\Git.Client\lib2Test\ConsoleApplication1\bin\Debug\D2Git\.git"; using (var repo = new Repository(wkDir)) { //此时必须保证存在 one.txt,two.txt 两个文件 string fname = "one.txt"; r

git for c#, commit本地,pushserver

//ok private static void push() { string wkDir = @"E:\DotNet2010\单位project\Git.Client\lib2Test\ConsoleApplication1\bin\Debug\D2Git\.git"; using (var repo = new Repository(wkDir)) { //此时必须保证存在 one.txt,two.txt 两个文件 string fname = "one.txt&quo

第二章-第二题(练习使用git的add/commit/push/pull/fetch/clone等基本命令)-By郭青云(未完待续)

题目描述: 每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 使用步骤: 未完待续...... 参考文件:http://blog.csdn.net/u012575819/article/details/50553501

第二章-第二题(每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令。比较项目的新旧版本的差别。)--by侯伟婷

第二题:每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. 下面我将自己的练习结果和个人感受记录如下: 第一步:安装Git,设置自己的账号和邮箱,参见Git教程-廖雪峰的官方网站,网址如下参考资料1所示. 第二步:在Git中新建repository,名叫HelloWorld,并进行初始化,如图所示. 第三步:在HelloWorld版本库中新建了helloWorld.txt文件,用以练习G

git取消本地commit

如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c505f4abe Author: zhyq0826 <[email protected]> Date: Tue Sep 4 18:19:23 2012 +0800 删除最近搜索数目限制 commit 8da0fd772c3acabd6e21e85287bdcfcfe8e74c85 Merge: 46

[Git] git revert ( revert commit 和 revert merge)

转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了revert命令帮助程序员修复这样的错误. 举个例子,下图是git commit 的历史记录 git revert 命令会通过一个新的commit 来使仓库倒退一个commit,在上例中,如果程序员想要revert 最新的那次commit (Updated to Rails 2.3.2 and edge h

通过git rebase修改commit message

今天发现一个项目的git commit message中的单词拼错了,需要修改一下.但这样简单的修改,需要通过git rebase才能完成. 首先要git rebase到需要修改message的那个commit的前1个commit.假设commit id是32e0a87f,运行下面的git rebase命令: git rebase -i 32e0a87f 在git bash中运行上面的命令后,会弹出编辑框,在编辑框中会分行依次显示以pick开头的这个commit之后的所有commit messa