I don't have any immediate solution, but a couple of points:
(1) If you are using "git gc" outside of Gerrit, I suggest that you only do it when Gerrit is stopped.
(2) I suggest you make sure you have a backup for you start trying to fix this.
When you say you get "error: refs/ does not point to a valid object!"
I don't know what command you are issuing to get that.
Is there anything in Gerrit's error_log?
When reporting problems, please try and be 100% clear, and copy/paste the exact command you issued, and the exact response you got (you can mask out (xxx) sensitive information if you need to).
Otherwise, we have to guess what you mean.