Matt Harasymczuk
Matt Harasymczuk

Reputation: 1778

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

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:

Upvotes: 35

Views: 74467

Answers (4)

yogesh_desai
yogesh_desai

Reputation: 483

I faced a similar issue but while doing go build or go mod tidy or go run. All the commands were giving me the same errors,

'error: refs/stash does not point to a valid object!'

I tried many things as below and including answers given above.

  1. git remote prune origin
  2. git stash
  3. rm .git/refs/stash .git/logs/refs/stash

Nothing worked for me. Finally, I deleted all the cache present in my system under path $GOPATH/go/pkg/mod/cache/, and I was able to resolve the issues.

Upvotes: 0

ShiningLight
ShiningLight

Reputation: 1143

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

Upvotes: 12

Matt Harasymczuk
Matt Harasymczuk

Reputation: 1778

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!

Upvotes: 44

kthompson
kthompson

Reputation: 892

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.

Upvotes: 1

Related Questions