1

Some intern did a force push on master yesterday. After we've done scolding, ;) we looked at the result. Luckily, we had an almost up to date version of the master on one machine, only some pull requests have to be merged again.

But one thing is bugging me: We found the old HEAD commit referenced in the last merged pull requests (on github), but since no branch or tag was pointing to it anymore, we couldn't find any way to either pull that commit (git pull origin <SHA1> didn't work) or to set a remote branch to that commit. Do you see any way to do that?

iGEL
  • 16,540
  • 11
  • 60
  • 74

2 Answers2

2

Assuming from your comment that you use GitHub.

You should ask GitHub techsupport to check the reflog of your GitHub project. If less than 30 days have passed your reflog will still contain the commit you are looking for. Just pass them the hash if you know it. Ask them to reset HEAD into this commit.

These links should be useful:

http://sitaramc.github.com/concepts/reflog.html

https://github.com/contact

P.S. If they give you a hint how to do it yourself - please, post it here as the answer.

Added: This is the great link on the subject: https://help.github.com/articles/commit-exists-on-github-but-not-in-my-local-clone

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • Well, it's easy if anyone of you still has the last commit before the breakage (recent checkout, access to that inter's machine), simply look [here](https://help.github.com/articles/commit-exists-on-github-but-not-in-my-local-clone). You should be able to get the SHA-1 of the last commit by simply looking at your module's recent commits list. If you're only missing a few commits, you could download them as diff's from github, then re-apply locally. Otherwise, simply contact github's support. – Martin Baulig Oct 18 '12 at 06:02
0

If you can see the commit on GitHub, e.g. at https://github.com/[org]/[repo]/commit/[sha] but it is orphaned, GitHub won't include it when you clone/fetch the repo.

If you change the URL slightly, though, to https://github.com/[org]/[repo]/tree/[sha], you can use the branch dropdown to create a branch at that commit:

recover lost commit

Chad
  • 2,378
  • 2
  • 26
  • 27