摆脱'...并没有指向旧git分支的有效对象'

Gal*_*eño 47 git version-control github

我有一个Git仓库的分支,我的克隆似乎有一个旧的,不再存在的分支的问题.我一直看到这个消息:

error: refs/heads/t_1140 does not point to a valid object!

我没有任何其他消息,回购工作正常.没有任何操作阻止我在其他分支上工作,推动变革,拉动等等.

我环顾四周,关于如何解决这个问题的指示并不明确.我试图执行,git fsck --full但我没有看到任何错误.只是加载dangling ...消息.

我也检查了我.git/config的,没有对这个分支的引用,也检查过.git/refs/heads,没有引用t_1140

知道如何摆脱这个错误吗?

ps我试图再次克隆我的回购,似乎错误也是我的Github回购.所以,我现在唯一能想到的就是放弃我的回购和再次分配.

Tor*_*rne 33

这将清除任何丢失的参考:

git for-each-ref --format="%(refname)" | while read ref; do
    git show-ref --quiet --verify $ref 2>/dev/null || git update-ref -d $ref
done
Run Code Online (Sandbox Code Playgroud)

  • 这可以安全地删除本地引用,而无需在远程上执行任何破坏性操作。删除“--quiet”标志和“2>/dev/null”以获得详细输出也有帮助。 (2认同)

Ada*_*ruk 25

检查.git/refs/remotes/origin.他们在那里,上游不再拥有它们.清除不再存在的遥控器

git remote prune origin
Run Code Online (Sandbox Code Playgroud)

您还可以--dry-run在实际执行之前通过添加来查看它的内容.

希望这可以帮助.

  • 西梅对我也不起作用。我所做的是导航到指定的文件夹“.git/refs/remotes/origin”,然后我只是删除了与我的错误消息匹配的文件。这使得错误消失了。 (4认同)

小智 25

我经常遇到这个错误.git remote prune起源对我不起作用.

[更新.AFAIU,我因为使用​​git alternate而遇到了这个问题.说我有回购A,注册为repo B的替代品.当我在回购A中创建一个新的分支br,并在回购B中将回购A作为远程获取时,git将创建一个远程ref .git/refs/remotes/A/br为新分支.当我在repo A中删除分支时,在相应的对象被垃圾收集后,我得到'错误:refs/remotes/A/br没有指向有效的对象!' ]

我编写了这个脚本(更新以处理打包引用)以删除悬空引用(使用Validate中的信息,如果提交存在).

#!/bin/sh

set -e

if [ $# -eq 0 ]; then
    dir="."
else
    dir="$1"
fi

if [ ! -d "$dir" ]; then
    echo "not a dir: $dir"
    exit 1
fi

if [ ! -d "$dir/.git" ]; then
    echo "not a git repo: $dir"
    exit 1
fi

cd "$dir"

files=$(find .git/refs -type f)

for f in $files; do
    id=$(cat "$f")
    if ! git rev-parse --quiet "$id" \
    >/dev/null 2>&1; then
    continue
    fi
    if ! git rev-parse --quiet --verify "$id^{commit}" \
    >/dev/null 2>&1; then
    echo "Removing ref $f with missing commit $id"
    rm "$f"
    fi
done

if [ ! -f .git/packed-refs ]; then
    exit 0
fi

packfiles=$(cat .git/packed-refs \
    | grep -v '#' \
    | awk '{print $2}')

for f in $packfiles; do
    if ! git rev-parse --quiet --verify "$f" \
    >/dev/null 2>&1; then
    continue
    fi
    id=$(git rev-parse "$f")
    if ! git rev-parse --quiet --verify "$id" \
    >/dev/null 2>&1; then
    continue
    fi
    if ! git rev-parse --quiet --verify "$id^{commit}" \
    >/dev/null 2>&1; then
    echo "Removing packed ref $f with missing commit $id"
    git update-ref -d $f
    fi
done
Run Code Online (Sandbox Code Playgroud)


Dan*_*dei 14

您的本地克隆可能没问题,问题是t_1140GitHub存储库中缺少分支对象.

我也有这个问题,GitHub支持修复它,我想通过删除refs/heads/t_1140它们的结尾.

更新:我再次使用另一个分支得到错误,我可以通过运行此命令来修复它:

git push origin :refs/heads/t_ispn982_master
Run Code Online (Sandbox Code Playgroud)

您应该收到如下警告消息:

remote: warning: Allowing deletion of corrupt ref.
Run Code Online (Sandbox Code Playgroud)

但损坏的分支将被删除


jai*_*vis 5

error: refs/heads/t_1140 does not point to a valid object!
Run Code Online (Sandbox Code Playgroud)

假设您已尝试使用以下方法进行修剪:

git remote prune origin

而且你仍然无法让它工作,作为最后的手段,尝试删除t_1140

基本上,

1. cd refs/heads

2. rm -r t_1140