-1

I have 6 commit in my project. I want go back to HEAD^3 and then try each commit one-by-one. I am searching to the code introducing bug in bead HEAD^3 to HEAD.

I tried with git checkout HEAD^3 but all the later changes are lost.

dead programmer
  • 4,223
  • 9
  • 46
  • 77
  • 2
    You want to use git bisect – Andrew C Jan 05 '16 at 15:12
  • 1
    What do you mean with "later changes are lost"? You have checked out an older commit. So the later commits will not be visible in the commit history when you do `git log`. This is expected. It does not mean that commits are lost. The commits are still present in the object database of your git repository. You can still do `git checkout ` or `git checkout ` to get back to the branch you were on before checking out HEAD^3. After that, you will see the entire history in `git log` once again. – Alderath Jan 05 '16 at 15:23

1 Answers1

3

I am searching to the code introducing bug in bead HEAD^3 to HEAD.

you should use git bisect for this task.

Annotating a file helps if you know where the issue is to begin with.
If you don’t know what is breaking, and there have been dozens or hundreds of commits since the last state where you know the code worked, you’ll likely turn to git bisect for help.

The bisect command does a binary search through your commit history to help you identify as quickly as possible which commit introduced an issue.

Let’s say you just pushed out a release of your code to a production environment, you’re getting bug reports about something that wasn’t happening in your development environment, and you can’t imagine why the code is doing that. You go back to your code, and it turns out you can reproduce the issue, but you can’t figure out what is going wrong.

You can bisect the code to find out. First you run git bisect start to get things going, and then you use git bisect bad to tell the system that the current commit you’re on is broken. Then, you must tell bisect when the last known good state was, using git bisect good [good_commit]...

Read [here] the full explanation on how to do it.


Here is a sample code on how to use it

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167