Git basics

Find the commit that broke something (git bisect)

Let Git jump through your history halfway at a time with git bisect until it finds the first commit that broke things.

Fill these in once
  1. Start the search
    Terminal
    git bisect start

    Git now waits for you to point out one bad commit and one good commit.

  2. Mark the current commit as broken
    Terminal
    git bisect bad
  3. Mark a commit you know worked
    Terminal
    git bisect good v1.2.0

    Git jumps to a commit halfway between the two. Check whether the problem is there.

  4. Tell Git if this commit works or not
    Terminal
    git bisect good

    Run git bisect bad instead if the problem shows up. Repeat on each commit Git picks until it names the first bad commit.

  5. Let a script do the checking
    Terminal
    git bisect run npm test

    Optional. The script should exit with 0 when things work and 1 when they are broken. Git then finds the bad commit on its own.

Check it worked

  1. See every answer you gave so far
    Terminal
    git bisect log
Undo it
  1. Stop and go back to where you started
    Terminal
    git bisect reset
  1. Start the search
    Terminal · Ubuntu / Debian
    git bisect start

    Git now waits for you to point out one bad commit and one good commit.

  2. Mark the current commit as broken
    Terminal · Ubuntu / Debian
    git bisect bad
  3. Mark a commit you know worked
    Terminal · Ubuntu / Debian
    git bisect good v1.2.0

    Git jumps to a commit halfway between the two. Check whether the problem is there.

  4. Tell Git if this commit works or not
    Terminal · Ubuntu / Debian
    git bisect good

    Run git bisect bad instead if the problem shows up. Repeat on each commit Git picks until it names the first bad commit.

  5. Let a script do the checking
    Terminal · Ubuntu / Debian
    git bisect run npm test

    Optional. The script should exit with 0 when things work and 1 when they are broken. Git then finds the bad commit on its own.

Check it worked

  1. See every answer you gave so far
    Terminal · Ubuntu / Debian
    git bisect log
Undo it
  1. Stop and go back to where you started
    Terminal · Ubuntu / Debian
    git bisect reset
  1. Start the search
    PowerShell
    git bisect start

    Git now waits for you to point out one bad commit and one good commit.

  2. Mark the current commit as broken
    PowerShell
    git bisect bad
  3. Mark a commit you know worked
    PowerShell
    git bisect good v1.2.0

    Git jumps to a commit halfway between the two. Check whether the problem is there.

  4. Tell Git if this commit works or not
    PowerShell
    git bisect good

    Run git bisect bad instead if the problem shows up. Repeat on each commit Git picks until it names the first bad commit.

  5. Let a script do the checking
    PowerShell
    git bisect run npm test

    Optional. The script should exit with 0 when things work and 1 when they are broken. Git then finds the bad commit on its own.

Check it worked

  1. See every answer you gave so far
    PowerShell
    git bisect log
Undo it
  1. Stop and go back to where you started
    PowerShell
    git bisect reset

New to commit? I explain it in plain English on Layman Terms.