Figure out when bug was introduced by reading previous git commits

I merged develop into 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.

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.

  • Rails: exclude anything from version control?
  • Specify folders to merge with git
  • Heroku: ! master -> master (non-fast-forward)
  • git clone through ssh returns Permission denied (publickey,password)
  • chef deployment?
  • Github API access to private repos using OAuth
  • Rugged and Grack: Finding commit before push
  • rails log issue
  • 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.

    Basically, git blame:

    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.

    Git Baby is a git and github fan, let's start git clone.