Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git refs/remotes/origin/master does not point to a valid object

Tags:

git

After the last merge to the master branch of my Git repository I have lost the ability to clone repository.

Cloning into test-repository...
remote: Counting objects: 126084, done.
remote: Compressing objects: 100% (28327/28327), done.
Receiving objects: 100% (126084/126084), 132.63 MiB | 29.30 MiB/s, done.
remote: Total 126084 (delta 96101), reused 126078 (delta 96095)
Resolving deltas: 100% (96101/96101), done.
error: refs/remotes/origin/master does not point to a valid object!
error: Trying to write ref refs/heads/master with 
       nonexistant object 951aca8051823b2f202d30c9cb05401ef17618c6

Fisheye, a repository hosting tool, is reporting:

Unable to fetch from remote repository:
/var/atlassian/application-data/fisheye/managed-repos/MYREPONAME.git
error: unable to find 0d998c99b6d01e8aabca72b1934802acf90b8fc9,
fatal: object 0d998c99b6d01e8aabca72b1934802acf90b8fc9 not found

The last commit in the repository on master branch is:

commit 0d998c99b6d01e8aabca72b1934802acf90b8fc9
Merge: a6ea4b3 1f373a9
Date:   Fri Dec 14 13:57:24 2012 +0200

Merge branch 'new_error_code'

I have tried:

cd /var/atlassian/application-data/fisheye/managed-repos/MYREPONAME.git
git gc
git fsck --full
git reflog expire --expire=0 --all
git update-ref
git gc --aggressive

The following questions did not help my case:

  • How to recover Git objects damaged by hard disk failure?
  • Fatal error after GitHub automatic merge
  • Listing and deleting Git commits that are under no branch (dangling?)
like image 403
Matt Harasymczuk Avatar asked Dec 14 '12 15:12

Matt Harasymczuk


People also ask

What is remotes origin master?

Origin is simply the name given to any remote repository available on GitHub. Whenever we need to push the changes to a remote repository, we use git push along with the remote repository “origin” and “master” branches. The term used is “git push origin master“.

What is remote master in git?

The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch.

What is git refs heads master?

git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch. For example, there is literally a file called master in that path that contains the commit ID of the tip of the master branch.

What is Git remotes origin head?

The word origin is an alias that Git created to replace the remote URL of a remote repository. It represents the default branch on a remote and is a local ref representing a local copy of the HEAD in the remote repository.


3 Answers

git gc
git fsck --full
git reflog expire --expire=0 --all
git update-ref -d 0d998c99b6d01e8aabca72b1934802acf90b8fc9
git gc --aggressive
git remote update --prune

and it worked!

like image 144
Matt Harasymczuk Avatar answered Oct 08 '22 11:10

Matt Harasymczuk


Providing explanation for Matt Harasymczuk's answer:

Perform garbage collection so Git can clean up the mess it's made of itself (More info on git gc here)

git gc

Verify the connectivity and validity of the objects in the database (More info on git fsck here)

git fsck --full

Prune all entries from the reference log (More info on git reflog here)

git reflog expire --expire=0 --all

Delete the reference to the named hash (More info on git update-ref here)

git update-ref -d <your hash here>

Run garbage collection again, throwing away all old deltas. This will take longer than the first time, but is much more thorough at optimizing the repository (More about aggressive garbage collection here)

git gc --aggressive

Update the list of remotes, deleting references to branches that no longer exist (More about git remote here)

git remote update --prune
like image 30
ShiningLight Avatar answered Oct 08 '22 12:10

ShiningLight


Typically you can do:

git reflog master

This will give you a list of the last know positions that master has pointed to.

Once you know this you can create a temporary branch to an older version of master ie

git branch temp master@{1}

Then checkout temp and see if it is in proper order. If you don't see anything there then the commands that you did previously (delete the reflog, delete dangling commits, etc) have probably wiped out all ways to recovery.

like image 38
MrUnleaded Avatar answered Oct 08 '22 11:10

MrUnleaded