HOWTO Investigate a "missing" commit from repository history
The problem
Often enough, we get reports that a given commit has gone missing from a given repository's git history. Often that's caused by a force push on unprotected branches, but This StackOverflow article describes how you can end up in this state without a force push as well.
A solution
It's possible to search through the sequence of pushes to a repository using the snippet below:
p = Project.find_by_full_path('u/p')
p.events.code_push.last(100).each do |e|
printf "%-20.20s %8s...%8s (%s)\n", e.push_event_payload[:ref], e.push_event_payload[:commit_from], e.push_event_payload[:commit_to], e.author.try(:username)
end
If you look at the output from running that snippet for the target branch, you will see a discontinuity in the from/to commits as you step through the output. Each new push should be "from" the "to" SHA of the previous push. When this discontinuity happens, you will see two pushes with the same "from" SHA.
Example application
TBD
Edited by Katrin Leinweber