7

Yesterday, we had a member of our team do a git push --force inside of our Bitbucket repository. I am aware of who it was, but I am wondering if it is possible to gather which commits were force pushed into the repository.

The information I am looking for from the git log / history is something like this -

+ 1951097...9b070f0 tower -> origin/tower (forced update)

I saw this message when I was trying to pull into my local branch and encountered merge conflicts after the force push, but I havent been able to see it anywhere else except that one time. Is there a place where I can see all of the commits (specifically ones with that (forced update) tag next to them?) Running Git reflog and git log do not seem to return this information.

I saw this post(which is hilarious) that is similar - How can I find out who force pushed in git?

Instead of looking for the specific person (like the asker in the previous question), I am just looking for the commits that were pushed into the repo with --force after I clone it locally. Is this information possible to gather, or am I out of luck?

Thanks.

J. Doe
  • 1,479
  • 5
  • 25
  • 49
  • 1
    If you can access the repository hosted in the server, you can see the reflogs there. Better to implement some access control like "not allow force push". – ElpieKay Dec 29 '17 at 08:59

1 Answers1

6

My old answer was about finding who did the forced push, not about what was force-pushed.

If you have access to the server, you should find a trace of the old commits (before the push) with git reflog.

From there, you can infer the new commits which replaced the old branch history.

Note that if you do not have access to the remote server (typically: github.com), you can still get the old branch SHA1 (the one before the forced push) with the "poor man's reflog", aka the push events (GitHub Events API).
See "Does github remember commit IDs?": look for any recent push events on the right branch: the last one would be the one forced, the previous one would represent the old SHA1 commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Well, yes, except that `core.logAllRefUpdates` defaults to *false* in a bare repository, and most server side repositories are bare. It looks like GitHub remembers more details than just hashes, so that must be done independently. – torek Dec 29 '17 at 17:23
  • @torek Yes, if we are talking about github.com, you will get a lot through the push events. – VonC Dec 29 '17 at 17:24