From 1e2c00889a76f44484f63205be65b076afe620e7 Mon Sep 17 00:00:00 2001 From: Chalarangelo Date: Tue, 13 Apr 2021 20:00:22 +0300 Subject: [PATCH] Add bisect snippets --- snippets/automatic-find-commit-with-bug.md | 29 +++++++++++++++++++++ snippets/manual-find-commit-with-bug.md | 30 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 snippets/automatic-find-commit-with-bug.md create mode 100644 snippets/manual-find-commit-with-bug.md diff --git a/snippets/automatic-find-commit-with-bug.md b/snippets/automatic-find-commit-with-bug.md new file mode 100644 index 000000000..ac465e76a --- /dev/null +++ b/snippets/automatic-find-commit-with-bug.md @@ -0,0 +1,29 @@ +--- +title: Automatically find the commit that introduced a bug +tags: commit,branch,advanced +--- + +Uses a binary search algorithm and a given script to find which commit in history introduced a bug. + +- Use `git bisect start` to start the process. +- Use `git bisect good ` to mark a `` as "good", indicating it is known to be bug-free. +- Use `git bisect bad ` to mark a different `` as "bad" indicating it has the bug. +- Use `git bisect run ` to run the given `` on each subsequent commit to find which commit introduce the bug. +- Use `git bisect reset` to reset to the original branch. You can optionally specify a `` to reset to. + +```sh +git bisect start +git bisect good +git bisect bad +git bisect run +git bisect reset [] +``` + +```sh +git bisect start +git bisect good 3050fc0de +git bisect bad c191f90c7 +git bisect run npm test # Run `npm test` for each commit +# ... some time later the bad commit will be printed +git bisect reset # Goes to the original branch +``` diff --git a/snippets/manual-find-commit-with-bug.md b/snippets/manual-find-commit-with-bug.md new file mode 100644 index 000000000..465002499 --- /dev/null +++ b/snippets/manual-find-commit-with-bug.md @@ -0,0 +1,30 @@ +--- +title: Manually find the commit that introduced a bug +tags: commit,branch,advanced +--- + +Uses a binary search algorithm to manually find which commit in history introduced a bug. + +- Use `git bisect start` to start the process. +- Use `git bisect good ` to mark a `` as "good", indicating it is known to be bug-free. +- Use `git bisect bad ` to mark a different `` as "bad" indicating it has the bug. +- Use `git bisect (bad | good)` marking each subsequent commit as "good" or "bad" depending if it has the bug or not. +- Use `git bisect reset` to reset to the original branch. You can optionally specify a `` to reset to. + +```sh +git bisect start +git bisect good +git bisect bad +git bisect (bad | good) +git bisect reset [] +``` + +```sh +git bisect start +git bisect good 3050fc0de +git bisect bad c191f90c7 +git bisect good # Current commit is good +git bisect bad # Current commit is buggy +# ... some time later the bad commit will be printed +git bisect reset # Goes to the original branch +```