警告:git push时出现重复的引用

4
当将主分支推送到远程目标tmp时:
git push tmp master

我收到了这条消息。
warning: Duplicated ref: refs/heads/master

推送仍然可以成功。

但这条消息是什么意思? 我怎样才能找到更详细的日志信息?

这是我的 .git/config 文件。

[core]
  repositoryformatversion = 0
  filemode = false
  bare = false
  logallrefupdates = true
  symlinks = false
  ignorecase = true
  hideDotFiles = dotGitOnly
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = git@github.com:testuser/myproject.git
[branch "master"]
  remote = origin
  merge = refs/heads/master
[remote "tmp"]
  url = git@192.168.1.44:testuser/myproject.git
  fetch = +refs/heads/*:refs/remotes/tmp/*

我的git版本是1.7.11.msysgit.1


show-refls-remote信息

$ git show-ref
1696d17186db41cc70876f76f943e18ea4708ad3 refs/heads/master
3c51688bf27e712001db1b6e9f316748634643c4 refs/remotes/origin/HEAD
3c51688bf27e712001db1b6e9f316748634643c4 refs/remotes/origin/master
1696d17186db41cc70876f76f943e18ea4708ad3 refs/remotes/tmp/master

$ git ls-remote tmp
warning: Duplicated ref: refs/heads/master
1696d17186db41cc70876f76f943e18ea4708ad3        HEAD
1696d17186db41cc70876f76f943e18ea4708ad3        refs/heads/master

$ git ls-remote origin
3c51688bf27e712001db1b6e9f316748634643c4        HEAD
3c51688bf27e712001db1b6e9f316748634643c4        refs/heads/master

在tmp上运行git show-ref的输出结果为:
$ git show-ref
warning: Duplicated ref: refs/heads/master
1696d17186db41cc70876f76f943e18ea4708ad3 refs/heads/master

在tmp上的packed-refs内容

# pack-refs with: peeled 
3c51688bf27e712001db1b6e9f316748634643c4 refs/heads/master
3c51688bf27e712001db1b6e9f316748634643c4 refs/heads/master

myproject.git 裸仓库中 find . 命令的输出结果。由于objects目录下的子目录过多,我没有将它们粘贴在这里。

$ find .
.
./branches
./packed-refs
./objects
./HEAD
./info
./info/exclude
./config
./description
./refs
./refs/tags
./refs/heads
./refs/heads/master
./hooks
./hooks/commit-msg.sample
./hooks/update.sample
./hooks/pre-commit.sample
./hooks/prepare-commit-msg.sample
./hooks/post-update.sample
./hooks/pre-rebase.sample
./hooks/post-receive
./hooks/pre-applypatch.sample
./hooks/update
./hooks/applypatch-msg.sample
1个回答

5

据我所知,这意味着你不知何故创建了另一个名为master的引用,但它并不在正常位置。我遇到这种情况的少数几次是因为我在操作管道命令时没有提供引用的完整路径(refs/heads/master),而该命令需要一个路径。首先,让我们使用以下命令将您的本地存储库与远程存储库同步:

git fetch --all

首先使用以下命令检查您的本地存储库:

git show-ref | grep -i master

由于你正在使用Windows,所以需要加上-i参数。因为大小写敏感可能会成为一个问题。我猜你在列表中看到的可能是refs/master之类的内容。这意味着有一个名称可以有两种解决方式。refs/remotes/origin/masterrefs/remotes/tmp/master是可以的,因为它们的命名空间正确。

如果还没有找到,请检查远程设置:

git ls-remote url://to/remote/repo.git | grep master

我怀疑问题出在你的本地代码库。对于本地代码库,你可以通过update-ref命令删除引用:

git update-ref -m 'remove duplicate ref' -d <duplicate ref>

当你使用show-ref命令时,<duplicate ref>就是你找到的多余引用。分支存储在refs/heads下。请注意不要删除refs/heads/master

如果它在远程上,你可以通过以下方式删除重复项:

git push origin :<duplicate ref>

当使用ls-remote命令后,找到了一个额外的重复参考<duplicate ref>。在这里要小心,不要使用masterrefs/heads/master.

如果可以,请更新问题,并附上git show-refgit ls-remote的输出。同时,我可以在评论中为您提供步骤,以确保不会丢失任何数据。

现在我们看到packed-refs是罪魁祸首

所以问题出在packed-refs有多行引用了master。我不确定这是如何产生的,但我怀疑有一个git版本允许它通过。执行git gc会导致packed-refs被重新编写,因此我建议在tmp远程上执行该命令。


谢谢回复。我添加了一些详细信息,似乎tmp有一个重复的引用。我应该只删除那个引用吗? - txworking
你是否直接访问tmp?我认为我们无法通过远程操作来解决这个问题。如果您有直接访问权限,让我们做几件事情。首先,进入那个仓库并运行git show-ref。我想它会像git ls-remote一样显示相同的内容,但让我们看看。其次,在裸仓库(myproject.git)中运行'find .'。最后,cat输出的packed-refs并使用这些输出更新您的答案。 - John Szakmeister
请注意,根据ls-remote的输出,我们可能会删除tmp上的refs/heads/master(可以通过git pushgit update-ref进行操作--后者需要访问服务器),然后让您从工作树重新推送到主分支。但是我想先确保没有其他问题。顺便问一下,tmp远程安装了哪个版本的git? - John Szakmeister
我更新了信息,ls-remotels-remote origin 的输出结果相同。 - txworking
tmp的git版本是1.7.9.5,本地版本是git version 1.7.11.msysgit.1。非常感谢。 - txworking
看起来在临时仓库上运行 git gc 命令就可以解决问题了。git gc 会重新打包对象和压缩引用,这将导致文件被重写而不再有重复的行。 - John Szakmeister

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