$ git checkout 14198
warning: refname '14198' is ambiguous.
Updating files: 100% (8963/8963), done.
Switched to branch '14198'
Your branch is up to date with 'origin/14198'.
why it warns "warning: refname '14198' is ambiguous."?? There is no same name tag, or remote branch names.
$ git branch -a | grep 14198
* 14198
IRS-14198
IRS-14198-API
IRS-14198-UI
remotes/origin/14198
remotes/origin/IRS-14198
remotes/origin/IRS-14198-API
remotes/origin/IRS-14198-UI
If I run "git tag -l | grep 14198", it returns nothing. so, there is no same name tag.
why?
Thank you all for your replies. appending more outputs here:
run git rev-list --all | grep 14198
returns nothing.
$ git rev-list --objects --all | grep 14198
....
....multiple line outputs.
....only one line starts with 14198
14198841b0cb3735a412142617c8dd77844a4606 file/path/filename
....
....
$ git cat-file -t 14198841b0cb3735a412142617c8dd77844a4606
blob
It's a blob(file), not a commit.
WOW!! Thank you everyone!!
I test it!!
If a branch name is same as a prefix-of-a-blob-id, git checkout will warn refname 'xxxxx' is ambiguous.
$ git checkout 14198841b0cb3735a412142617c8dd77844a4606
fatal: reference is not a tree: 14198841b0cb3735a412142617c8dd77844a4606
$ git checkout 14198841b0cb3735a412142617c8dd77844a4606
fatal: reference is not a tree: 14198841b0cb3735a412142617c8dd77844a4606 is id of a blob(not a commit). so, checkout failed.
looks like a hidden incorrect-warning-message in git checkout
.
checked git source code
if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
if (refs_found > 0) {
warning(warn_msg, len, str);
if (advice_enabled(ADVICE_OBJECT_NAME_WARNING))
fprintf(stderr, "%s\n", _(object_name_msg));
}
free(real_ref);
}
return 0;
}
./environment.c:33:int warn_on_object_refname_ambiguity = 1;
warn_on_object_refname_ambiguity is set to 1. don't know whether there is a command line switch to turn it off.
forget about. it's 0:36am. I am going to sleep.
Thanks everyone!!
CodePudding user response:
You have a commit with a hash that starts with the same sequence as the branch name you provided.
Try running git rev-list --all --abbrev-commit --abbrev=5
. That will list the commit hashes in your repo (beware the list may be very big if you have a long history).
You can also grep
the list of refs for the hash you are looking for.
$ git rev-list --all | grep 14198
You can also check the commit log to know what it refers to before creating a branch or tag:
$ git log -1 14198
That will always show the commit that refers to a branch or tag if present, otherwise it will show a commit with a matching hash.