Getting rid of '… does not point to a valid object' for an old git branch

前端 未结 13 1999
不知归路
不知归路 2020-12-13 03:51

I have a fork of a Git repo and my clone appears to have an issue with an old, no longer existant, branch. I keep seeing this message:

error: refs/heads/t_1140

相关标签:
13条回答
  • 2020-12-13 04:03

    I'm giving my two cents for whoever is using Visual Studio. I had this issue while trying to delete a local branch and running the following command through the command line solved it:

    git branch -D <branchName>
    
    0 讨论(0)
  • 2020-12-13 04:04

    Check .git/refs/remotes/origin. They are there and the upstream no longer has them. To clean out the remotes that no longer exist run

    git remote prune origin
    

    You could also see what it would to by adding --dry-run before actually doing it.

    0 讨论(0)
  • 2020-12-13 04:07

    If it's failing with this:

    error: failed to run repack

    Look in .git/packed-refs for the listed branch(es) and remove those lines. I tried all the other solutions, but this finally solved it for me.

    0 讨论(0)
  • 2020-12-13 04:08

    After trying various solutions, I finally got the references cleaned up on Windows command prompt with the following:

    for /f %i in ('git for-each-ref --format="%(refname)"') do git show-ref --quiet --verify %i || git update-ref -d %i
    
    0 讨论(0)
  • 2020-12-13 04:09

    I had this issue when attempting to clone some github repositories, the system I was on was running an older version of git v1.7.4, a quick update fixed it up.

    remote: Counting objects: 533, done.
    remote: Compressing objects: 100% (248/248), done.
    remote: Total 533 (delta 232), reused 529 (delta 230)
    Receiving objects: 100% (533/533), 121.36 KiB, done.
    Resolving deltas: 100% (232/232), done.
    error: refs/remotes/origin/master does not point to a valid object!
    verror: Trying to write ref refs/heads/master with nonexistant object 0457f3e2e9432e07a1005f0f4161dc4b8215f128
    fatal: Cannot update the ref 'HEAD'.
    
    0 讨论(0)
  • 2020-12-13 04:15

    You say that you have:

    also checked .git/refs/heads and there's no reference to t_1140

    ... which is very surprising. I can only see how this error would occur if the file .git/refs/heads/t_1140 exists. Is it possible you were mistaken about this?

    Correction: Charles Bailey points out below that the refs might be packed, in which case there is no corresponding file in .git/refs/heads

    0 讨论(0)
提交回复
热议问题