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:
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“.
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.
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.
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.
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!
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With