All Projects → pnavarrc → Howto Git Bisect

pnavarrc / Howto Git Bisect

Licence: mit
Find bugs quickly with `git bisect`

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Howto Git Bisect

Golang For Nodejs Developers
Examples of Golang compared to Node.js for learning
Stars: ✭ 2,698 (+9892.59%)
Mutual labels:  learning, howto
Golang Examples
Go(lang) examples - (explain the basics of #golang)
Stars: ✭ 1,070 (+3862.96%)
Mutual labels:  learning, howto
Story
Base package to create stories for PySchool
Stars: ✭ 16 (-40.74%)
Mutual labels:  learning
Ros Academy For Beginners
中国大学MOOC《机器人操作系统入门》代码示例 ROS tutorial
Stars: ✭ 861 (+3088.89%)
Mutual labels:  learning
Launcher3
Launcher3 with no drawer
Stars: ✭ 25 (-7.41%)
Mutual labels:  learning
Mex Vocabulary
MEX Vocabulary: a lightweight machine learning interchange format
Stars: ✭ 19 (-29.63%)
Mutual labels:  learning
7days Golang
7 days golang programs from scratch (web framework Gee, distributed cache GeeCache, object relational mapping ORM framework GeeORM, rpc framework GeeRPC etc) 7天用Go动手写/从零实现系列
Stars: ✭ 9,275 (+34251.85%)
Mutual labels:  learning
Ko.javascript.info
Modern JavaScript Tutorial in Korean (모던 JavaScript 튜토리얼)
Stars: ✭ 822 (+2944.44%)
Mutual labels:  learning
Gobook
A complete introduction into Go, superseded by https://github.com/miekg/learninggo
Stars: ✭ 882 (+3166.67%)
Mutual labels:  learning
Tiled
📕TILed is medium to share your day to day learning with the world
Stars: ✭ 25 (-7.41%)
Mutual labels:  learning
Algo.js
A Very Basic into Intermediate Algorithm Lesson
Stars: ✭ 11 (-59.26%)
Mutual labels:  learning
Scala Koans
An unofficial refreshed version of Scala Koans
Stars: ✭ 23 (-14.81%)
Mutual labels:  learning
Python examples
Learn Python by Examples.
Stars: ✭ 20 (-25.93%)
Mutual labels:  learning
Pytorch Forecasting
Time series forecasting with PyTorch
Stars: ✭ 849 (+3044.44%)
Mutual labels:  learning
Learning
Learn by building
Stars: ✭ 19 (-29.63%)
Mutual labels:  learning
Memo
👻 A free online book for frontend developer
Stars: ✭ 12 (-55.56%)
Mutual labels:  learning
Abstractionlayers
Abstraction Layers
Stars: ✭ 16 (-40.74%)
Mutual labels:  learning
Django Bookworm
A fun project to store my learning from each book that I read.
Stars: ✭ 23 (-14.81%)
Mutual labels:  learning
Workshops mathematics
Share resources, assets and information for the math sessions 🚀
Stars: ✭ 26 (-3.7%)
Mutual labels:  learning
Cryptoinscriber
📈 A live cryptocurrency historical trade data blotter. Download live historical trade data from any cryptoexchange, be it for machine learning, backtesting/visualizing trading strategies or for Quantopian/Zipline.
Stars: ✭ 27 (+0%)
Mutual labels:  learning

How to Use git bisect

Find the change that introduced a bug in your code, quickly.

The git bisect command helps you to find which change introduced a bug in your code. It’s easy and quick, but most people don’t know about it.

The Problem

You notice that in the most recent commit (let’s say 4a4e), a feature is not working, and you remember that at some point in the past (let’s say commit f8a4) it was working just fine. The task is to find out which commit introduced the bug.

The Solution: Git Bisect

Git uses the bisection algorithm to help you search the offending commit. To start, you need to mark a bad commit and a good commit, git will checkout a commit in the middle for you to test. Then you mark it either as good or bad, and then the process starts again.

We start by identifying a good (900d) and a bad (bad0) commit

step1

Git will keep the commits that are both descendants of the good commit and ancestors of the bad commit, which will leave us with a smaller graph to work with.

step2

Git chooses a commit between the good and bad commits. As this is a directed acyclic graph, there is no commit “in the middle”, git chooses the commit that will provide more information once tested.

step3

Now we need to test this commit as being good or bad. Let’s say it was bad, we mark it as such and git proposes a new commit to be tested. The graph now is smaller.

step4

We test this commit as well (let’s say it was good). In this case, the upper branch is removed from the commits to test, as we are under the assumption that only one commit introduced the bug.

step5

We test the next commit (it was good) and git proposes the last comit to be tested.

step6

We test this last commit and we are done, the first bad commit was b3fd.

step7

Example

To start the process, just invoke git bisect start and mark the commit as bad, and mark a commit that was working f8a4 as good.

(4a4e) $ git bisect start
(4a4e) $ git bisect bad
(4a4e) $ git bisect good f8a4

Bisecting: 7 revisions left to test after this (roughly 3 steps)
[cae5] Rename function

Git will checkout a commit in the middle, you need to test your code to see if this version is working:

(cae5) $ node add.js 1 2 3  // 6
(cae5) $  git bisect good

Bisecting: 7 revisions left to test after this (roughly 3 steps)
[0bca] Rename function

Git will checkout a version in the middle, you test again and mark it as good or bad. After a couple of steps, you will find the offending commit:

# 3 or 4 steps later ...

(90d0) $ git bisect bad

5e3c is the first bad commit
commit 5e3c
Author: Pablo Navarro Castillo <[email protected]>  // <- me 😊
Date:   Sat Apr 16 11:02:21 2016 -0300

    read all input arguments

:100755 100755 f111 d7fc M	add.js

(5e3c) $ git bisect reset

Now that we know which commit is the bad one, we can look at the diff to see what changed:

$ git show 5e3c5e

commit 5e3c
Author: Pablo Navarro Castillo <[email protected]>
Date:   Sat Apr 16 11:02:21 2016 -0300

    read all input arguments

diff --git a/add.js b/add.js
index f1110f6..d7fc703 100755
--- a/add.js
+++ b/add.js
@@ -8,7 +8,7 @@ function toInt(num) {
 // Parse the input arguments
 function readNumbers(input) {
   var numArgs = input.length;
-  return input.slice(2, numArgs).map(toInt);
+  return input.slice(1, numArgs).map(toInt);
 }

 // Read and parse command line arguments

The next step is to fix the bug, commit and

Learn more

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].