Month: July 2012

Code Tips

Git Error : (does not point to a valid object)

A friend of mine IMed me the other day to ask if I had ever seen an error like the one below:

error: unable to find e291a84831b445ba982539cc63a418126f0b5364
error: refs/heads/master does not point to a valid object!
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly

I had not, but it seemed plain enough. It appeared that the head of the master branch was pointing to a commit that didn’t actually exist in the repository. I don’t know for sure how this happened, but my friend’s team suspected a disrupted internet connection on push as one theory.

I Googled the error and found suggestions like “make a new remote” and “clone to a new branch, push, delete master, rename new branch”. This seemed like just too much work. There had to be an easier solution.

I was unable to clone the remote to my own machine (I got that same error on trying) and the team was in another state, so – short of a screensharing session – I couldn’t easily work with them on the problem.

I had the developer who had done the last known valid commit before this error send me the most recent 5 items output from the “git log” command and got the following (edited for privacy):

commit b65f24a64e78b38d193aa545d7b184fe26330a4c
Author: Joe Developer <joed@somewhere.com>
Date:   Fri Jul 27 10:05:53 2012 -0400

    Moved foo.jar to libs folder

commit 32b15424509881760667a77b615cc91e8e31afb9
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 21:45:46 2012 -0400

    Load swf files

commit bfac8d86c20ebbcac22af4e599e5815b0586f3d0
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 19:18:25 2012 -0400

    Navigation bug fixes

commit 60c5ff87435861157e56d948e09c63ad2f4db520
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:52:36 2012 -0400

    post merge

commit 1a97d137a51c6cd34825e4c9bc705620dfff7712
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:24:40 2012 -0400

    initial commit

Because Git is based in the file system, I could literally navigate to the remote file system and go to the ProjectName.git folder and into the refs/heads/ folder and find the master file (no extension). Inside was one string, the offending e291a84831b445ba982539cc63a418126f0b5364. I just replaced that string with the hash of the latest valid commit – b65f24a64e78b38d193aa545d7b184fe26330a4c – and then saved.

After that, I could clone the repo and the developers could pull, merge, and push their own changes. They were using DropBox in this instance as a “poor man’s remote” and upon further reflection, I have to wonder if that is what caused the conflict. Perhaps there was a problem with DropBox syncing all of the files and maybe a race condition at some point that resulted in a corruption? I know DropBox isn’t a perfect “remote server” solution, but a lot of people use it for certain circumstances, so this might be something to look out for.

If anyone else has seen this error and has a better fix than the one described here, then please leave a comment and let me know.