Skip to content

Ambiguous 实参

错误信息

                fatal: ambiguous 实参 'x': 两者都 revision and filename
              

快速摘要

name 你 provided matches 两者都分支/提交 and file — Git 做不 know 哪个你平均值.

为什么发生

  • file and 分支 share 相同 name

  • file and 标签 share 相同 name

  • filename 能是 interpreted as 提交 hash

最小示例

✗ 错误代码
git log main  # fatal: ambiguous argument 'main': both revision and filename
✓ 修复代码
# If you mean the branch:
git log refs/heads/main
# If you mean the file:
git log -- main

Use refs/heads/<name> for 分支 or -- <name> for files 到 disambiguate 当 names collide.

如何诊断

  • 检查如果 name exists as 两者都 file and 分支: ls <name> && git 分支 | grep <name>

  • 检查如果它是也标签: git 标签 | grep <name>

如何修复

  • Use -- 到 separate paths 从 revisions: git log <name> -- (treats as file) or git log -- <name>

  • Use 完整 ref path: git log refs/heads/<name> for 分支

  • Rename file or 分支到 avoid collision

如何预防

  • Avoid naming files 相同 as 分支 or 标签

  • Use -- 到 disambiguate paths 从 revisions in commands

相关资源

相关术语

相关课程

← 返回语言