I have this bug that showed up in my iOS app somewhere in the last 10 commits. I've tried looking at every single change I've made using a diff tool but can't figure it out.
Now I want to roll back to every version one by one to find what was the last version that did not have a bug, hoping that that way I can single out the problem.
What is the best way to rollback to the previous versions while keeping my latest commit safe.
I would recommend using git bisect
for tracking down bugs.
The general idea is, if you have a rough idea of when a bug appeared, git can do a binary search for the commit that caused the bug. The documentation has lots of examples and detailed explanation. A quick example:
git bisect # Start the bisect process
git bisect bad # This tells git bisect that the current commit is "bad", as in the bug is exhibited
git bisect good <commit hash> # This tells git bisect that <commit hash> doesn't exhibit the bug, so we only need to search between "good" and "bad". This would be your commit hash from 10 commits ago as mentioned in your question.
After that, git will check out a commit. You would then compile it, run it, whatever, then use git bisect good
or git bisect bad
to tell git whether or not the bug is exhibited. It will use this feedback to pin down the exact commit that introduced the "bad" behavior.
You can also use git bisect reset
to cancel the bisect process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With