git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Minor Bug in git cat-file (git 2.50)?
@ 2025-08-10 14:52 Jon Forrest
  2025-08-11  8:54 ` Patrick Steinhardt
  2025-08-11 15:09 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Jon Forrest @ 2025-08-10 14:52 UTC (permalink / raw)
  To: git

(Sorry if you see this more than once)

I'm using 'git cat-file' to show the example. This is probably not a
command-specific problem.

The problem is that using a deliberately ambiguous object ID produces
surprising output. This is a minor issue.

% git --version
git version 2.50.GIT
% uname -a
Linux fedora 6.15.9-201.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Aug  2 
11:37:34 UTC 2025 x86_64 GNU/Linux

% git init

# depending on where you run the test, might not be necessary
% git config --global --add safe.directory /tmp

Initialized empty Git repository in /tmp/.git/
% echo a > a.txt
% git add a.txt
% git ls-files -s
100644 78981922613b2afb6025042ff6bd878ac1994e85 0       a.txt	
% git cat-file -t 78981922613b2afb6025042ff6bd878ac1994e85
blob

# All is well so far.

% pushd .git/objects/78
% ls
981922613b2afb6025042ff6bd878ac1994e85
# create a new file with the same name as the file that already exists,
# except change the final letter to something else.
% cp 981922613b2afb6025042ff6bd878ac1994e85 
981922613b2afb6025042ff6bd878ac1994e86
% ls
981922613b2afb6025042ff6bd878ac1994e85 
981922613b2afb6025042ff6bd878ac1994e86
% popd
# use an ambiguous SHA1 prefix
# why does the next command produce two identical hints, both of which
# are incorrect?
% git cat-file -t 78981922613b2afb6025042ff6bd878ac1994e8
error: short object ID 78981922613b2afb6025042ff6bd878ac1994e8 is 
ambiguous  # this is correct
hint: The candidates are:
hint:   7898192 blob
hint:   7898192 blob
fatal: Not a valid object name 78981922613b2afb6025042ff6bd878ac1994e8
# I would have expected:
hint:   78981922613b2afb6025042ff6bd878ac1994e85 blob
hint:   78981922613b2afb6025042ff6bd878ac1994e86 blob
# using the supplied hint doesn't work, which is no surprise
% git cat-file -t 7898192
fatal: Not a valid object name 7898192

Cordially,
Jon Forrest




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-11 19:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 14:52 Minor Bug in git cat-file (git 2.50)? Jon Forrest
2025-08-11  8:54 ` Patrick Steinhardt
2025-08-11 19:10   ` Jon Forrest
2025-08-11 15:09 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).