Question

I have a repository on GitHub located here. I created a working branch for someone and they forked the repo, made some changes on the working branch and submitted a pull request.

I tried the changes and everything was good and since GitHub was offering to automatically merge the pull request, I went ahead and click the big, green "Merge Pull Request" button. All was well there except that the changes to the working branch were applied to the master branch which I can live with.

The problem is now that the repository cannot be fetched by me or anyone else. I get this error:

dp@dpub:/tmp/gh$ git clone git://github.com/dapphp/securimage.git
Initialized empty Git repository in /tmp/gh/securimage/.git/
remote: Counting objects: 333, done.
remote: Compressing objects: 100% (269/269), done.
remote: Total 333 (delta 91), reused 297 (delta 55)
Receiving objects: 100% (333/333), 3.91 MiB | 2.78 MiB/s, done.
Resolving deltas: 100% (91/91), done.
error: refs/remotes/origin/master does not point to a valid object!
error: Trying to write ref refs/heads/master with nonexistant object 31d684d383913c4cf1a0d5ff0691c2c163284a35
fatal: Cannot update the ref 'HEAD'.

This results in no directory being created or any working files getting downloaded. I've searched all over for possible ways to resolve this but most talk about issuing commands to the git repo which I cannot do because I can't get a copy of the repo in the first place.

I've found I can still clone a remote branch using something like this: git clone -b audiofixes git://github.com/dapphp/securimage.git but I still get an error about the bad ref and I can't figure out any commands I can run to fix the problem. I'm willing to undo the changes if necessary.

In case it helps, once I clone a different branch, here is the output of git branch -a:

* audiofixes
  remotes/origin/2.0.2
  remotes/origin/3.0
  remotes/origin/HEAD -> origin/master
  remotes/origin/audiofixes
  remotes/origin/securimage_flash

At this point I really have no idea what (if anything) I can do to fix the state of the repository.

Thanks for any suggestions.

EDIT: Some command output as requested.

$ ls .git/refs/remotes/origin
HEAD

$ ls .git/objects
info/  pack/
# info is empty, pack has pack-b8add06e9a6864ea44a58c06b8bd549eedd90c94.idx and pack-b8add06e9a6864ea44a58c06b8bd549eedd90c94.pack

$ cat .git/refs/remotes/origin/master
cat: .git/refs/remotes/origin/master: No such file or directory

$ cat .git/refs/remotes/origin/HEAD 
ref: refs/remotes/origin/master
Was it helpful?

Solution

NEW:

Apparently 1) github does not give ssh access :(, and 2) it's impossible to share reflogs between different machines through git protocol.

So... You already created a ticket apparently, but you don't necessarily need them to fix the repository. All you need is for them (since they have privileged access) to run git reflog master on the server's repo and then paste the results for you to view. In that file, look for the previous SHA-1 value of master (since the current one doesn't seem to work). Once you have that, you (I think) can do the following (on your own computer):

$ git checkout -b temp
$ git update-ref refs/heads/temp $SHA1
$ git push -u origin +temp:master

This will undo the merge operation on the server.

You may be able to get the previously working SHA1 without having to get the reflog from the server. In your local repo (or your friend's local repo), the previously working commit does exist somewhere in there. If you can figure out a way to find it there, then you can proceed with the above suggestion.

OLD: Here is my first thought. If you are able to copy the .git/logs directory from the server, then that will have stored in it all the previous values of the master branch. Specifically, the file .git/logs/refs/heads/master will be a raw text file with the previous values of that branch. For example (I don't know if github allows you to do this or not):

$ git clone https://github.com/dapphp/securimage.git -b audiofixes
$ scp github.com:/dapphp/securimage.git/logs/refs/heads/master .git/logs/refs/remotes/origin/master
$ git update-ref refs/remotes/origin/master refs/remotes/origin/master@{1} #see "Date Spec" section of http://book.git-scm.com/4_git_treeishes.html

that should theoretically change the value to what master was previously. However it will only do that locally and will not actually change the value on the server, which is what we really need. So if you could ssh directly to the server and just run that last command there, that would (again, theoretically) fix the problem for good by simply undoing the merge.

.

This is all that I can think of on top of my head. But I really like solving git puzzles like this, so I'll let it sit in my head for a bit longer :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top