Gitlab CI job is failing with a “fatal: reference is not a tree” error

I have a gitlab ci job that keeps failing with a "fatal: reference is not a tree" error.

The output I get:

gitlab-ci-multi-runner 0.6.0 (4c26bc5)
Using Shell executor...
Running on hostname...

Fetching changes...
Checking out 821371a7 as master...
fatal: reference is not a tree: <ssha hash>

ERROR: Build failed with: exit status 1

I just tried removing the /home/gitlab-runner/builds/project directory. Then pushed a new commit. And the build succeeded.