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.
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.
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