3

I was attempting a repeated git filter branch which left a final message saying refs/heads/master is unchanged. I read that it was because a backup already existed so I had to get rid of it. So I ran git update-ref -d refs/heads/master and now there are no commits anymore and I can't seem to undo this. Any suggestions?

1 Answers1

2

I managed to fix this by reading this Stack Overflow question and the subsequent link in the comment: Recovering Git repository from objects only.

  1. use git fsck to find a list of dangling commit hashes

  2. vim into your .git/refs/heads/master which is just a text file and enter the suspected hash which represents your latest commit for master.

  3. save and go back to the root directory to inspect the git log to see if that is your latest. If not then systematically go through the hashes from step 1 until you found it.

  4. after finding it git checkout . so git reverts to the original state of the master branch

jub0bs
  • 60,866
  • 25
  • 183
  • 186