It lets you look inside Git objects like commits, trees, blobs, and tags to see their content or type.
Click to reveal answer
beginner
How do you use git cat-file to show the type of an object?
Use git cat-file -t <object-hash> to display the object type (commit, tree, blob, or tag).
Click to reveal answer
beginner
How can you see the full content of a Git object with git cat-file?
Use git cat-file -p <object-hash> to pretty-print the content of the object.
Click to reveal answer
beginner
What types of Git objects can git cat-file inspect?
It can inspect commits, trees (folders), blobs (files), and tags.
Click to reveal answer
intermediate
Why would you use git cat-file instead of normal Git commands?
To see the raw data stored inside Git objects, which helps understand how Git stores your project history.
Click to reveal answer
Which option with git cat-file shows the object type?
A-t
B-p
C-s
D-e
✗ Incorrect
The -t option prints the type of the object.
What does git cat-file -p <hash> do?
APretty-prints the object content
BPrints the object size
CPrints the object type
DChecks if the object exists
✗ Incorrect
The -p option pretty-prints the content of the object.
Which Git object type represents a file's content?
Atree
Bblob
Ccommit
Dtag
✗ Incorrect
A blob stores the content of a file.
If you want to see the size of a Git object, which git cat-file option do you use?
A-t
B-p
C-s
D-e
✗ Incorrect
The -s option shows the size of the object in bytes.
What is the main reason to inspect Git objects with git cat-file?
ATo delete objects
BTo merge branches
CTo create new commits
DTo see raw data inside Git
✗ Incorrect
It helps you see the raw data Git stores for commits, files, and folders.
Explain how you would use git cat-file to find out what type of object a hash represents and then see its content.
Use -t to get type, then -p to see content.
You got /3 concepts.
Describe the different Git object types and what git cat-file can show you about each.
Think about files, folders, commits, and tags.
You got /6 concepts.
Practice
(1/5)
1. What does the command git cat-file -t <object> display?
easy
A. The type of the Git object (e.g., commit, tree, blob)
B. The size of the Git object in bytes
C. The content of the Git object
D. The commit message of the latest commit
Solution
Step 1: Understand the -t option and differentiate from others
The -t flag in git cat-file shows the type of the object, such as commit, tree, or blob. The -s option shows size, and -p shows content.
Final Answer:
The type of the Git object (e.g., commit, tree, blob) -> Option A
Quick Check:
-t shows type = A [OK]
Hint: Use -t to see object type quickly [OK]
Common Mistakes:
Confusing -t with -s or -p options
Expecting content instead of type
Thinking it shows commit messages
2. Which of the following is the correct syntax to display the content of a Git object using git cat-file?
easy
A. git cat-file -p <object>
B. git cat-file -s <object>
C. git cat-file -t <object>
D. git cat-file --show-content <object>
Solution
Step 1: Identify the option for content display and verify others
The -p option in git cat-file prints the content of the object in a human-readable form. -s shows size, -t shows type, and --show-content is not a valid option.
Final Answer:
git cat-file -p <object> -> Option A
Quick Check:
-p shows content = A [OK]
Hint: Use -p to print object content [OK]
Common Mistakes:
Using -s or -t instead of -p for content
Typing invalid options like --show-content
Confusing size with content display
3. Given a Git blob object with hash abc123 containing the text "Hello World", what will be the output of git cat-file -p abc123?
medium
A. blob
Hello World
B. Error: object not found
C. abc123
D. Hello World
Solution
Step 1: Understand -p output for blob objects and confirm format
The -p option prints the content of the object. For a blob, it prints the raw file content, here "Hello World". No extra labels like "blob" or the hash are printed, only the content itself.
Final Answer:
Hello World -> Option D
Quick Check:
Blob content = Hello World = D [OK]
Hint: Blob content prints raw text with -p [OK]
Common Mistakes:
Expecting type or hash in output
Confusing -p with -t or -s output
Assuming error if object exists
4. You run git cat-file -p 123xyz but get the error: fatal: Not a valid object name 123xyz. What is the most likely cause?
medium
A. The repository is corrupted
B. You used the wrong option; -p is invalid
C. The object hash 123xyz does not exist in the repository
D. You need to add the object to the index first
Solution
Step 1: Analyze the error message and rule out other causes
The error "Not a valid object name" means Git cannot find the object with the given hash. -p is valid, repository corruption is less likely without other errors, and objects do not need to be added to the index to be inspected.
Final Answer:
The object hash 123xyz does not exist in the repository -> Option C
Quick Check:
Invalid object hash = C [OK]
Hint: Check object hash exists before using cat-file [OK]
Common Mistakes:
Assuming -p is invalid option
Thinking repository is corrupted without proof
Believing objects must be indexed first
5. You want to first check the type, then the size of a Git object with hash def456 and finally print its content. Which sequence of commands correctly achieves this?
Step 1: Identify correct individual commands and required sequence
-t shows type, -s shows size, and -p prints content. Each must be run separately with the object hash in the order: type first, then size, then content. Sequences starting with size or content first do not match, and combining multiple flags in one command is invalid syntax.