다음 cee157
과 같은 2 개의 다른 커밋 ID를 참조 할 수있는 경우
cee157eb799af829a9a0c42c0915f55cd29818d4
과 cee1577fecf6fc5369a80bd6e926ac5f864a754b
입력하면 Git에서 경고 git log cee157
합니까? (또는 Git 1.8.5.2 (Apple Git-48)를 사용하면 입력 할 수 있습니다 git log cee1
).
나는 그것이 권위있는 출처를 찾을 수는 없지만 그래야한다고 생각합니다.
답변
그것은 당신에게 다음과 같은 것을 줄 것입니다 :
$ git log cee157
error: short SHA1 cee157 is ambiguous.
error: short SHA1 cee157 is ambiguous.
fatal: ambiguous argument 'cee157': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
방금 다음과 같이 중복 접두사가있는 커밋을 찾아 실제 Git 저장소에서 이것을 테스트했습니다.
git rev-list master | cut -c-4 | sort | uniq -c | sort -nr | head
이것은의 개정 목록을 가져 와서 master
처음 4자를 잘라 내고 나머지는 버리고 복제본을 세고 숫자로 정렬합니다. ~ 1500 커밋의 상대적으로 작은 저장소에서 일반적인 4 자리 접두사가있는 수정본이 상당히 많았습니다. Git에서 지원하는 가장 짧은 법적 길이 인 것 같아서 4 자리 접두사를 선택했습니다. (모호하지 않더라도 3 자리 이하로 작동하지 않습니다.)
그러나 이것은 오타가 아니기 때문에 중복 SHA1 (2와 3으로 시도)의 수에 관계없이 모호한 SHA1에 대한 오류 메시지가 두 번 나타나는 이유를 모르겠습니다.
error: short SHA1 cee157 is ambiguous.
error: short SHA1 cee157 is ambiguous.
(모두 켜짐 stderr
. 실제로 전체 출력은 켜져 stderr
있지만 아무것도 켜지지 않습니다 stdout
.)
Windows에서 테스트 :
$ git --version
git version 1.8.1.msysgit.1
버전이 1.8.1 이상인 경우 Git 이 중복에 대해 경고 한다고 말하는 것이 안전하다고 생각합니다 . (복제본으로 작동하지 않을 것입니다.) 훨씬 오래된 버전도 이런 식으로 작동했다고 생각합니다.
최신 정보
이 테스트 할 때, 당신은 때문에, 4 자리 SHA1의 최소 필요 int minimum_abbrev = 4
에 environment.c . ( 그것을 지적 해 준 @devnull 에게 감사드립니다 !)
답변
원래 포스터는 다음과 같이 말합니다.
나는 그것이 권위있는 출처를 찾을 수는 없지만 그래야한다고 생각합니다.
신뢰할 수있는 소스는 소스 코드에서 찾을 수 있습니다 get_short_sha1()
.
인용 이 :
if (!quietly && (status == SHORT_NAME_AMBIGUOUS))
return error("short SHA1 %.*s is ambiguous.", len, hex_pfx);
그리고 이것 :
if (!ds->candidate_checked)
/*
* If this is the only candidate, there is no point
* calling the disambiguation hint callback.
*
* On the other hand, if the current candidate
* replaced an earlier candidate that did _not_ pass
* the disambiguation hint callback, then we do have
* more than one objects that match the short name
* given, so we should make sure this one matches;
* otherwise, if we discovered this one and the one
* that we previously discarded in the reverse order,
* we would end up showing different results in the
* same repository!
*/
ds->candidate_ok = (!ds->disambiguate_fn_used ||
ds->fn(ds->candidate, ds->cb_data));
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
또한 기능이 예상대로 작동하는지 테스트 하기도합니다.