Skip to content

Instantly share code, notes, and snippets.

@egyjs
Created January 13, 2023 15:42
Show Gist options
  • Save egyjs/138b9303ebb05253727139a2f81f6a12 to your computer and use it in GitHub Desktop.
Save egyjs/138b9303ebb05253727139a2f81f6a12 to your computer and use it in GitHub Desktop.
Useful tips

One useful Git tip is to use the command "git stash", to find the commit that introduced a bug in your code. This command allows you to perform a binary search through your commits to quickly locate the commit that caused the bug.

For example, let's say you have a bug in your code and you know it was not present in a previous version. You can use the command "git bisect" to start the search process:

$ git bisect start

Then you can specify the last known good commit and the current commit where the bug was introduced:

$ git bisect good <good_commit_hash>

$ git bisect bad <bad_commit_hash>

Git will then automatically check out a commit in the middle of the range and ask you if the bug is present or not. Based on your answer, Git will automatically check out the next commit and ask you again. This process will continue until the commit that introduced the bug is found.

Once the bad commit is found, you can use the command

$ git bisect reset

to return to the branch you were working before starting the bisect process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment