Figure out when bug was introduced by reading previous git commits
feature and then found a bug and now I am trying to figure out how it got there. If I run
git checkout develop and then run a test, the bug is not there. If I run
git checkout feature and then run a test, the bug is there.
I started going back through the commit history in my feature branch by running
git log and then
git checkout <commit>; rspec for every commit I made on that feature branch and they all have the bug. The thing is, that includes the commit on develop from which I first made the feature branch! More specifically, if I run
git checkout feature; git checkout 555555; rspec the test fails. If I run
git checkout develop; git checkout 555555; rspec the test passes.
- Using forked (and patched) Rails 2-3-stable from git woes
- Change github repository for Rails
- Error: fatal: Not a git repository (or any parent up to mount point /app)
- Adding folders to .gitignore
- How to push/deploy project on digital ocean without git clone
- Setting up Github on a new computer
I thought commit numbers uniquely identify code bases. How can a commit have different code depending on whether you check it out from a feature branch or a develop branch? Moreover, how can I figure out where in my commit history I actually introduced the bug? Obviously, I did not introduce the bug before creating the feature branch that off of develop.
2 Solutions collect form web for “Figure out when bug was introduced by reading previous git commits”
To figure out which was the commit that introduced a bug, just find out the offending lines in your codebase, and do a
git blame on the files invloved to figure out the commit id and the committer.
Annotates each line in the given file with information from the revision which last modified the line.
Once you have the offending commits, you can find out all relevant details about when and how and by whom they were introduced and so on.
Regarding the changes not being present in the develop branch but in your feature branch, it is possible that some merge/rebase conflicts occurred, which were not correctly resolved, and the bad merge was the reason why the bug was introduced.
EDIT: As the OP mentions in comments below, a bad merge where the conflict was not resolved correctly caused this.
Your case seems to be ideal for git bisect. https://www.kernel.org/pub/software/scm/git/docs/git-bisect.html