NoMethodError: undefined method `commits_count' for nil:NilClass

https://sentry.gitlab.net/gitlab/gitlabcom/issues/1201500/

NoMethodError: undefined method `commits_count' for nil:NilClass
  merge_request.rb:421:in `commits_count'
    merge_request_diff.commits_count
  gitlab/metrics/instrumentation.rb:161:in `block in commits_count'
    .measure { super }
  gitlab/metrics/method_call.rb:36:in `measure'
    retval = yield
  gitlab/metrics/instrumentation.rb:161:in `commits_count'
    .measure { super }
  projects/merge_requests_controller.rb:60:in `block (2 levels) in show'
    @commits_count = @merge_request.commits_count
...
(140 additional frame(s) were not displayed)

NoMethodError: undefined method `commits_count' for nil:NilClass

Summary

After customer ran BFG on the repo, all of the merge requests, that have commits before running BFG, return 500 error. Repository cleanup didn't help.

This is affecting SMB Bronze customer with 4 seats: https://gitlab.zendesk.com/agent/tickets/145062 (internal)

Edited by Sokunrotanak Srey (Rotanak)