0
0
Gitdevops~20 mins

git cat-file to inspect objects - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Cat-File Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Inspecting a commit object with git cat-file
You have a commit hash abc1234. What is the output type when you run git cat-file -t abc1234?
Git
git cat-file -t abc1234
Acommit
Bblob
Ctree
Dtag
Attempts:
2 left
💡 Hint
The -t option shows the type of the object.
💻 Command Output
intermediate
1:30remaining
Viewing the content of a blob object
You want to see the content of a file stored as a blob object with hash def5678. Which command shows the file content?
Git
git cat-file -p def5678
Agit cat-file -s def5678
Bgit cat-file -t def5678
Cgit cat-file -p def5678
Dgit cat-file -e def5678
Attempts:
2 left
💡 Hint
The -p option pretty-prints the object content.
Troubleshoot
advanced
2:00remaining
Error when inspecting a non-existent object
You run git cat-file -p 1234567 but get the error: fatal: Not a valid object name 1234567. What is the most likely cause?
Git
git cat-file -p 1234567
AThe repository is corrupted and cannot read objects
BYou used the wrong option; -p is invalid
CYou need to run git fetch before using git cat-file
DThe object hash 1234567 does not exist in the repository
Attempts:
2 left
💡 Hint
Check if the hash exists in the repo.
🧠 Conceptual
advanced
1:30remaining
Understanding git cat-file -s output
What does the command git cat-file -s 9a8b7c6 output?
Git
git cat-file -s 9a8b7c6
AThe type of the object identified by 9a8b7c6
BThe size in bytes of the object identified by 9a8b7c6
CThe content of the object identified by 9a8b7c6
DThe commit message of the commit object 9a8b7c6
Attempts:
2 left
💡 Hint
The -s option shows size.
Best Practice
expert
2:30remaining
Using git cat-file in a script to check object type
You want a script to check if a given hash is a tree object. Which command correctly returns true if the object is a tree, and false otherwise?
Atest "$(git cat-file -t $HASH)" = "tree" && echo true || echo false
Bif git cat-file -p $HASH | grep -q tree; then echo true; else echo false; fi
Cgit cat-file -s $HASH | grep tree && echo true || echo false
Dgit cat-file -e $HASH && echo true || echo false
Attempts:
2 left
💡 Hint
Use -t to get the object type exactly.