Git pull失败:“错误:refs/stash指向无效的对象!”

16

git pull 出现了以下错误:

$ git pull
error: refs/stash does not point to a valid object!
error: refs/stash does not point to a valid object!
error: refs/stash does not point to a valid object!
error: refs/stash does not point to a valid object!
Current branch mybranch is up to date.

我尝试过这个解决方案,但对我无效。 更新的信息:

$ GIT_TRACE=1 git pull 
trace: exec: 'git-pull'
trace: run_command: 'git-pull'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--is-bare-repository'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'ls-files' '-u'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'config' '--bool' 'branch.mybranch.rebase'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'rev-parse' '--verify' 'HEAD'
trace: built-in: git 'update-index' '-q' '--ignore-submodules' '--refresh'
trace: built-in: git 'diff-files' '--quiet' '--ignore-submodules'
trace: built-in: git 'diff-index' '--cached' '--quiet' '--ignore-submodules' 'HEAD' '--'
trace: built-in: git 'rev-parse' '-q' '--git-dir'
trace: built-in: git 'rev-parse' '-q' '--verify' 'refs/remotes/origin/mybranch'
trace: built-in: git 'merge-base' '53512e9ce3faa7c78b6d5d7ba1a63e56b5a42a11' 'refs/heads/mybranch'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'fetch' '--update-head-ok'
error: refs/stash does not point to a valid object!
trace: run_command: 'ssh' 'git@git-master' 'git-upload-pack '\''function-test'\'''
error: refs/stash does not point to a valid object!
trace: run_command: 'rev-list' '--verify-objects' '--stdin' '--not' '--all' '--quiet'
trace: run_command: 'rev-list' '--verify-objects' '--stdin' '--not' '--all'
trace: exec: 'git' 'rev-list' '--verify-objects' '--stdin' '--not' '--all'
trace: built-in: git 'rev-list' '--verify-objects' '--stdin' '--not' '--all'
error: refs/stash does not point to a valid object!
error: refs/stash does not point to a valid object!
trace:...

不确定这是否有帮助。但请尝试运行命令 git remote prune origin - usha
1
请执行 $ GIT_TRACE=1 git pull 命令,并更新您的问题,包括用于调用 git fetch(即 git pull 执行的第一件事)的实际 refspec。 - kostix
@Vimsha:$ git remote prune origin 返回错误信息:error: refs/stash does not point to a valid object! - Jaime M.
git remote prune origin 对我有用! - Blairg23
4个回答

52

最简单的方法是完全清除你的存储。请注意,你需要删除两个文件——而不是链接解决方案中概述的一个文件:

rm .git/refs/stash .git/logs/refs/stash

2
rm .git/refs/... 对我有用,谢谢 @mockinterface。 - monteirobrena
1
之后我必须运行 git stash,然后错误消失了。 - Dmitry Gryazin
最终我通过在整个.git目录中进行文本搜索并删除所有引用来解决了这个问题。 - Cordell
我正在使用 git-gui 0.21 版本的 Windows,当我点击菜单 Repository -> Visualize master's history 时,它显示了错误信息。但是我按照以下步骤操作后,错误信息消失了,希望不会再出现。 - tttony

1

我刚遇到了这个错误。 两个服务器从同一源拉取克隆;只有其中一个出现了此错误。 所以我深入挖掘。

Git的版本1.8.5.5的发行说明中指出:

  • “git clone”无法从直接位于“refs /”下的存储库(例如“refs / stash”)克隆,因为不同的验证路径对此类refname执行不同的操作。 放宽客户端侧的验证以允许这样的引用。

我发现其中一个服务器正在使用Git 1.7.1,而另一个正在使用Git 1.8.5.6。

值得注意的是,尽管上面的发行说明没有明确提到,但fetch命令也会失败。


在我的情况下,我发现安装了Git 1.7.1的服务器实际上也有更新的Git版本,但是它在PATH环境变量中排名较低。值得注意的是,当我使用更新的版本运行git fetch时,即使使用旧版本,克隆操作之后也能正常工作。
最简单的解决方法就是将Git升级到1.8.5.5版本或更高版本。
当然,也可以放弃暂存,但这样一来,下次有人暂存时,你的克隆仓库又会出问题。

1

我尝试了所有建议的解决方案,但都没有解决问题。最终解决方法非常简单:

# Made a small change in a code-file with vim

# stash'ed it then
git stash

# got it back
git stash pop

# reverted my small change
git checkout .

# finish, no more error
git pull

这可能并不适用于每个人,或者在没有按照此前的其他修复措施进行的情况下可能不起作用。 但是值得一试。


1

我遇到了类似的问题,但是在执行go buildgo mod tidy或者go run时。所有的命令都给我报同样的错误:

'error: refs/stash does not point to a valid object!'

我尝试了很多方法,如下所示:

  1. git remote prune origin
  2. git stash
  3. rm .git/refs/stash .git/logs/refs/stash

但是没有任何一种方法对我有效。最终,我在路径$GOPATH/go/pkg/mod/cache/下删除了系统中所有的缓存,然后问题得到了解决。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接