引用名称不明确,拉取失败。

8
我运行了以下命令,因为我想把我的生产分支移回去,而不必先检出:
git branch -f production HEAD~1

现在我在结账生产环境时遇到了以下警告:

warning: refname 'production' is ambiguous.

我接下来运行:

git pull

我收到了以下错误信息:

First, rewinding head to replay your work on top of it...
Fast-forwarded production to 7463e01c536ad52746b8879ef3d70ffd5a8db31e.
error: Ref refs/heads/production is at 252038dfa22caba8a816a68dcb005c625e44c51f but expected ae5b621609c1b5b430e3d30711157298f842942a
fatal: Cannot lock the ref 'refs/heads/production'
Could not move back to refs/heads/production

我可以在其他分支上操作。如何解决这个问题?

更多信息

git tag 没有返回任何输出。我之前有一个生产库,但现在已将其重命名为 live。

> ~/repo (chris-membership-fees)$ git show-ref | grep production
88e0c37c9ae4ff6967ddd027b62b62fa2c0ac272 refs/heads/production
9d739cff44a898f0c68da33fb22a230985e479ce refs/remotes/backup/production

~/repo (chris-membership-fees)$ git branch -a | grep production
  production
  remotes/backup/production

日志

我将第一个版本标记为a,第二个版本标记为b(请注意,由于生产环境已更改,修订号已更改)。这是经过装饰简化的日志。

* commit 7463e01c536ad52746b8879ef3d70ffd5a8db31e (**tag: a**, backup/live-master, production, live-master)
| 
| Date:   Wed Dec 28 11:47:49 2011 +1100
| 
|     Merge remote-tracking branch 'origin/joseph-quick-fix'
|  
* commit f35f0259c4e36d46dd1df71b3293bef6105cef98 (origin/hotfix-googleplusdirectconnect)
| 
| Date:   Fri Dec 23 12:25:27 2011 +1100
| 
|     Add google plus link tag to home page for direct connect
|    
*   commit 8b3a30ef2909439ac18b65ebbb316eb0cdd2d61c
|\  Merge: f696f3e 88e0c37
| | 
| | Date:   Wed Dec 21 14:28:45 2011 +1100
| | 
| |     Merge branch 'master' into chris-hotfix
| |   
* | commit f696f3e2b8f4a19ec2b2c2a3638c68e7a52836e3 (origin/chris-hotfix, backup/chris-hotfix, chris-hotfix)
| | 
| | Date:   Wed Dec 21 11:56:10 2011 +1100
| | 
| |     Fixed buyer price info
| |     
| *   commit 88e0c37c9ae4ff6967ddd027b62b62fa2c0ac272
| |\  Merge: c9655da ae5b621
| |/  
|/|   Date:   Wed Dec 21 11:53:36 2011 +1100
| |   
| |       Merge branch 'master' of git.freelancer.com:production into production
| |   
* | commit ae5b621609c1b5b430e3d30711157298f842942a (HEAD, **tag: b**)
| | 
| | Date:   Wed Dec 21 10:51:47 2011 +1100
| | 
| |     Merge branch 'master' of git.freelancer.com:production
| |   
| * commit c9655da9c1627ab53720ae818affdd1e6f14119f (origin/game-shadow2)
| | 
| | Date:   Tue Dec 20 18:41:57 2011 -0500
| | 
| |     * Removed debugging code
| |     
| *   commit ca88d33538bd3b99ea7c186b5b531e611847989d
| |\  Merge: 99e983a c397a8b
| |/  
|/|   Date:   Tue Dec 20 17:25:24 2011 -0500
| |   
| |       Merge remote-tracking branch 'production/master' into shadow2

git branch -a 的输出是什么? - Andrew Marshall
2
你也可以使用 git show-ref 来展示所有未缩写的引用。 - Lily Ballard
你使用的是哪个版本的Git? - Mark Longair
3个回答

7

感谢 Git 邮件列表 上的 Johannes Sixt。

最有可能的原因是您在 .git 目录中直接拥有一个 'production' 引用。也许您或您的脚本无意中使用 'git update-ref production ae5b621' 创建了它,即没有给出完整的引用路径名。

实际上,它并不在 .git 根目录中,但我在 branches 中有一个空的 production 文件夹。


我在使用git-update-ref时不小心创建了一个名为“master”的文件,这导致了同样的问题。简单的解决方法是删除.git/master文件。感谢提示。 - davidA

6
> ~/repo (chris-membership-fees)$ git show-ref | grep production
88e0c37c9ae4ff6967ddd027b62b62fa2c0ac272 refs/heads/production
9d739cff44a898f0c68da33fb22a230985e479ce refs/remotes/backup/production
88e0c37c9ae4ff6967ddd027b62b62fa2c0ac272 refs/remotes/production/master

refs/heads/production由于refs/remotes/production而变得模糊不清。解决方法是通用的,与引用类型前缀无关,因此分支、标签、远程甚至自定义引用名称都不能发生冲突。


1
我将“production”重命名为“live”,因此现在只显示前两个结果,但我仍然看到了冲突。 - Casebash
你的意思是 error: Ref refs/heads/live is at 252038dfa22caba8a816a68dcb005c625e44c51f but expected ae5b621609c1b5b430e3d30711157298f842942al,还是 warning: refname 'live' is ambiguous. - Ismael Luceno
@Casebash:1)你目前处于一个游离状态的 HEAD,这就是为什么会出现拉取错误的原因。因为你已经移动了当前所在的分支(我们都以为你还在其他分支上),所以你基本上是在同一分支上但是不同的“时间点”。 - Ismael Luceno
@Casebash:现在你应该切换到另一个分支并返回到生产环境,或者执行git reset。这将解决你的问题 :)。 - Ismael Luceno
虽然不完全是答案,但我还是因为你的努力授予了你赏金。 - Casebash
显示剩余5条评论

5
如果您只想删除警告:
git config --global core.warnambiguousrefs false

出现警告是因为您有一个名为production的分支和一个名为production的远程。最好将其中之一重命名为其他名称。


我认为这并不太合理 - 当我阅读 git rev-parse 文档时,只有当 refs/remotes/production/HEAD 存在时,production 远程才会产生歧义,而这并没有显示在 git show-ref 输出中。 - Mark Longair
@Mark:你说得对。我把“production”改名为“live”,但是我仍然看到模糊警告。 - Casebash
@manojlds:谢谢,现在我在生产分支上进行拉取时也遇到了问题。 - Casebash

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