摆脱旧 git 分支的“...不指向有效对象”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6265502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting rid of '... does not point to a valid object' for an old git branch
提问by Galder Zamarre?o
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:
我有一个 Git 存储库的分支,我的克隆似乎有一个旧的、不再存在的分支的问题。我一直看到这条消息:
error: refs/heads/t_1140 does not point to a valid object!
error: refs/heads/t_1140 does not point to a valid object!
I don't have any other messages and the repo works fine. There's no operation that stops me from working on other branches, pushing changes, pulling...etc.
我没有任何其他消息,而且 repo 工作正常。没有任何操作可以阻止我在其他分支上工作、推送更改、拉取...等。
I've looked around and there's less than clear instructions on how to get around this issue. I've tried to execute git fsck --full
but I see no errors. Just a load on dangling ...
messages.
我环顾四周,关于如何解决这个问题的说明并不明确。我试图执行,git fsck --full
但我没有看到任何错误。只是dangling ...
消息负载。
I've also checked my .git/config
and there's no references to this branch and have also checked .git/refs/heads
and there's no reference to t_1140
我也检查过我.git/config
的,没有提到这个分支,也检查过.git/refs/heads
,没有参考t_1140
Any idea how to get rid of this error?
知道如何摆脱这个错误吗?
p.s I've tried to clone my repo again and it seems like the error is my Github repo too. So, the only thing I can think of right now is to ditch my repo and fork again.
ps我再次尝试克隆我的回购,似乎错误也是我的 Github 回购。所以,我现在唯一能想到的就是再次放弃我的回购和分叉。
回答by TdV
I run into this error on a regular basis. git remote prune origin does not work for me.
我经常遇到这个错误。git remote prune origin 对我不起作用。
[ Update. AFAIU, I'm running into this problem because of using git alternate. Say I've got repo A, registered as alternate for repo B. When I create a new branch br in repo A, and fetch repo A as remote in repo B, git will create a remote ref .git/refs/remotes/A/br for the new branch. When I delete the branch in repo A, and after the corresponding object is garbage-collected, I get the 'error: refs/remotes/A/br does not point to a valid object!' ]
[ 更新。AFAIU,由于使用 git 替代,我遇到了这个问题。假设我有 repo A,注册为 repo B 的替代。当我在 repo A 中创建一个新分支 br,并在 repo B 中获取 repo A 作为远程时,git 将创建一个远程 ref .git/refs/remotes/A /br 用于新分支。当我删除 repo A 中的分支,并在相应的对象被垃圾收集后,我收到“错误:refs/remotes/A/br 未指向有效对象!” ]
I've written this script (updated to deal with packed refs) to remove the dangling refs (using the info in Validate if commit exists).
我已经编写了这个脚本(更新以处理打包的 refs)来删除悬空的 refs(使用Validate if commit exists 中的信息)。
#!/bin/sh
set -e
if [ $# -eq 0 ]; then
dir="."
else
dir=""
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 }')
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
回答by Adam Dymitruk
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/refs/remotes/origin
。他们在那里,上游不再有他们。清除不再存在的遥控器运行
git remote prune origin
You could also see what it would to by adding --dry-run
before actually doing it.
您还可以通过--dry-run
在实际执行之前添加来查看它的作用。
回答by Dan Berindei
Your local clone is probably fine, the problem is that the t_1140
branch objects are missing from your GitHub repository.
您的本地克隆可能没问题,问题是t_1140
您的 GitHub 存储库中缺少分支对象。
I had this problem too and GitHub support fixed it, I think by deleting refs/heads/t_1140
on their end.
我也遇到了这个问题,GitHub 支持修复了它,我认为是refs/heads/t_1140
在他们的末尾删除。
Update:I got the error again with another branch and I was able to fix it by running this command:
更新:我在另一个分支上再次遇到错误,我能够通过运行以下命令来修复它:
git push origin :refs/heads/t_ispn982_master
You should get a warning message like this:
您应该收到如下警告消息:
remote: warning: Allowing deletion of corrupt ref.
but the corrupted branch will be deleted
但损坏的分支将被删除
回答by Tor Arne
This will clean out any missing refs:
这将清除任何丢失的参考:
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
回答by Mark Longair
You say that you have:
你说你有:
also checked .git/refs/heads and there's no reference to t_1140
还检查了 .git/refs/heads 并且没有提到 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?
...这是非常令人惊讶的。如果文件.git/refs/heads/t_1140
存在,我只能看到这个错误是如何发生的。你有没有可能误解了这一点?
Correction:Charles Bailey points out below that the refs might be packed, in which case there is no corresponding file in .git/refs/heads
更正:Charles Bailey 在下面指出 refs 可能被打包,在这种情况下没有相应的文件.git/refs/heads
回答by codemonkee
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.
我在尝试克隆一些 github 存储库时遇到了这个问题,我使用的系统运行的是旧版本的 git v1.7.4
,快速更新修复了它。
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'.
回答by Tarka
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.
查找.git/packed-refs
列出的分支并删除这些行。我尝试了所有其他解决方案,但这终于为我解决了。
回答by Cordell
Do a text search through your .git directoryfor your branch
通过您的 .git 目录为您的分支进行文本搜索
Use something like grep
or findstr
and remove all instances.
使用类似grep
或的东西findstr
并删除所有实例。
回答by Frank Forte
This fixed it for me:
这为我修复了它:
git push origin :refs/remotes/origin/[branch name]
git push origin :refs/heads/origin/[branch name]
WARNING: this deletes the branch from the server - any changes on that branch that have not been merged to another branch will be lost.
警告:这将从服务器中删除分支 - 该分支上尚未合并到另一个分支的任何更改都将丢失。
回答by Eddy
I had this problem and none of the remedies suggested above worked. So I edited .git/packed-refs and removed the line that mentioned the non-existent branch. All was suddenly well.
我遇到了这个问题,上面建议的补救措施都没有奏效。所以我编辑了 .git/packed-refs 并删除了提到不存在分支的行。一切都突然好了。
Gotta love those human-readable file formats ...
一定要喜欢那些人类可读的文件格式......