📢 Tip of the day
#Git lovers.
What if there is a bug introduced in the code but you don't know which commit introduced the bug?
No worries, here is one procedure which help you to find it.😎
Procedure-
1) git bisect start- starts the searching procedure to find the bad commit.
2) (Optional) Use the command git bisect good <hash-code of the commit that you are sure doesn't have the bug>- usually this is the first or the second commit and tells git to start from the middle.
3) git will start checking out commits on its own, you have to test the commit and let git know if the commit has the bug or not by using commands,git bisect good- if the commit is fine
git bisect bad- if the commit has the bug.
4) After giving feedback, git has a feedback tree that it uses to return the commit that introduced the bug/ the first bad commit, you can copy its hash code. The reference refs/bisect/bad will be left pointing at that commit.
5) After a bisect session, to clean up the bisection state and return to the original HEAD, issue the following command:
git bisect reset- By default, this will return your tree to the commit that was checked out before git bisect started.
6) git bisect reset <commit>- For example, git bisect reset bisect/bad will check out the first bad revision, while git bisect reset HEAD will leave you on the current bisection commit and avoid switching commits at all.
7) git revert <hash-code of the bad commit>- used to revert the changes done in the bad commit that introduced the bug in the code.
Important note:- Before executing the procedure kindly read the functional details of bisect as this helps you a lot especially when and in which case you can use this command.
Reference -
git-scm.com/docs/git-bisect
#git #gitcommand #bisect