17

Can somebody help me to solve this problem. I had made a previous post about this but I couldn't solve it through those answers. Please help:)

I have tried to run git fsck --full and I get :

Checking object directories: 100% (256/256), done. error: HEAD: invalid sha1 pointer 15044de63184bed22f9be9f48fd63a3a7652eea4 error: refs/heads/master does not point to a valid object! notice: No default references dangling blob f4ffb48ece75b45ec593146216a2ecae5a5b2194 dangling blob f37ffd41d80a2d07258d0b8fa7118d236d480fc0 dangling blob f1ff1fa538a538d9085e573f60ad11e8e7f5395e dangling blob f9ff6bdaf08fdbf9001ff44d2aa1a49092c20ad1 dangling blob f97f1a223ef3ca33f55d51ae25d98d3b5b2f9ece 
10
  • maybe this post will help? stackoverflow.com/questions/17274575/… Commented Sep 11, 2014 at 21:57
  • You should be able to just git checkout master (or any other branch name) to get a valid HEAD ref for your working copy. Commented Sep 11, 2014 at 21:57
  • I have tried it I get this fatal: reference is not a tree: master Commented Sep 11, 2014 at 22:01
  • Also, have you tried git gc ? Commented Sep 11, 2014 at 22:02
  • 10
    TWO OF THE SUGGESTIONS ABOVE ARE DEFINITELY BAD IDEAS IF YOU HAVEN'T BACKED EVERYTHING UP. git gc is not likely to fix anything, however it cleans up anything that Git thinks it might be finished with. This makes it much less likely that you will be able to reverse recent changes or find lost versions of files which you care about. git checkout master will replace your file tree with master branch. However, if you have the above problem your recent commits may have been lost. Checking out master means that your only record of your local branch changes (the files themselves) is destroyed. Commented Jun 16, 2015 at 14:08

6 Answers 6

21

In my case, I edited .git/refs/remotes/origin/HEAD. I couldn't get git update-ref to work, but that seems to be the recommended way.

So if git checkout (<branch> | <commit>) doesn't work, you should try something like git update-ref HEAD ref:master or just try editing .git/HEAD.

Sign up to request clarification or add additional context in comments.

2 Comments

This was the only thing that worked for me -- /refs/remotes/origin/HEAD was referencing a branch that had been deleted.
I've been able to go to an unbroken branch by updating .git/HEAD and had git log again from there.
16

I had the same problem. Simply doing a git pull origin master fixed it, and left my local edits intact.

Comments

3

"invalid sha1 pointer" in combination of git gc was seen before (git for windows issue 423)

git 2.7 (Q4 2015) will fix this:

See commit 14886b4, commit 8c845cd (28 Sep 2015) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 1018f3e, 15 Oct 2015)

"git gc" used to barf when a symbolic ref has gone dangling (e.g. the branch that used to be your upstream's default when you cloned from it is now gone, and you did "fetch --prune").

More precisely:

pack-objects: do not get distracted by broken symrefs

It is quite possible for, say, a remote HEAD to become broken, e.g. when the default branch was renamed.

We should still be able to pack our objects when such a thing happens; simply ignore broken symrefs (because they cannot matter for the packing process anyway).

Comments

0

It's always best to revert back a working version from a remote copy of the repository as stated by @henrikstroem:

git pull origin master 

Set your HEAD to another commit in your repository

If there's no remote copy of the repository at all, you might want to set your HEAD to another commit in your repository. This can be needed if you accidentally deleted the object of your current HEAD-commit.

  1. List all commit objects in your repository:
git cat-file --batch-all-objects --batch-check \ | grep 'commit' \ | cut -d' ' -f1 \ | git log --stdin --pretty='format:%C(auto)%H %ad %s' --date=iso 
  1. Check that the commits look reasonable, copy the commit-hash to use.
  2. Set the selected commit as the head of the master branch:
echo <commit-hash> > .git/refs/heads/master git checkout master 
  1. Check if everything is ok:
git fsck --full 

Comments

0

if you are facing this issue git fetch will resolve it

git fetch 

Comments

-7

I had the same problem that appened to me because of some problems with git objects. The only way to fix them is to do a git clone in a different folder and then copy-paste all in the old folder.

I will lee you know if i will find a different solution.

Regards

2 Comments

This might be a way to fix them, but it certainly isn't the only way.
I managed to fix a similar problem without doing git clone and starting again, which meant that I kept my branches and commits. See my answer stackoverflow.com/a/30872027/1737957

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.