Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a Git tag?
A Git tag is a label that points to a specific commit. It helps mark important points like releases or versions in the project history.
Click to reveal answer
beginner
How do you create a lightweight tag on a specific commit?
Use the command git tag <tagname> <commit-hash>. This creates a simple tag pointing to that commit without extra information.
Click to reveal answer
intermediate
What is the difference between lightweight and annotated tags in Git?
Lightweight tags are simple pointers to commits. Annotated tags store extra info like tagger name, date, and message, and are stored as full objects in Git.
Click to reveal answer
intermediate
How do you create an annotated tag on a specific commit?
Use git tag -a <tagname> <commit-hash> -m "message". This adds a message and extra info to the tag.
Click to reveal answer
beginner
How can you push a specific tag to a remote repository?
Use git push origin <tagname> to send the tag to the remote repository so others can see it.
Click to reveal answer
Which command creates a lightweight tag on commit abc123?
Agit commit -m "tag v1.0"
Bgit tag -a v1.0 abc123 -m "version 1.0"
Cgit tag v1.0 abc123
Dgit push origin v1.0
✗ Incorrect
Option C creates a lightweight tag named v1.0 on commit abc123.
What extra information does an annotated tag include?
ACommit hash only
BBranch name
CRemote URL
DTagger name, date, and message
✗ Incorrect
Annotated tags store tagger name, date, and a message along with the commit reference.
How do you push all tags to the remote repository?
Agit push origin --tags
Bgit push origin master
Cgit push origin HEAD
Dgit tag push
✗ Incorrect
The command 'git push origin --tags' pushes all local tags to the remote.
Which command creates an annotated tag with a message?
Agit tag v1.0
Bgit tag -a v1.0 -m "release"
Cgit tag -d v1.0
Dgit push origin v1.0
✗ Incorrect
Option B creates an annotated tag with the message 'release'.
If you want to tag a commit but don’t remember its hash, what can you do?
AUse git log to find the commit hash
BUse git push
CUse git branch
DUse git clone
✗ Incorrect
You can use 'git log' to see commit history and find the commit hash to tag.
Explain how to create and push an annotated tag on a specific commit in Git.
Think about tagging with extra info and sharing it with others.
You got /4 concepts.
Describe the difference between lightweight and annotated tags and when you might use each.
Consider the detail and purpose of the tag.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of tagging a commit in Git?
easy
A. To delete a commit permanently
B. To label a specific commit for easy reference later
C. To merge two branches automatically
D. To create a new branch from the commit
Solution
Step 1: Understand what a tag does
A tag in Git is a label that points to a specific commit, making it easy to find later.
Step 2: Compare options with tag purpose
Deleting commits, merging branches, or creating branches are different Git actions unrelated to tagging.
Final Answer:
To label a specific commit for easy reference later -> Option B
Quick Check:
Tag = label commit [OK]
Hint: Tags mark commits for quick access later [OK]
Common Mistakes:
Confusing tags with branches
Thinking tags delete commits
Assuming tags merge code
2. Which of the following commands correctly tags a commit with hash abc123 as v1.0?
easy
A. git tag -m v1.0 abc123
B. git tag abc123 v1.0
C. git tag v1.0 abc123
D. git commit tag v1.0 abc123
Solution
Step 1: Recall git tag syntax
The correct syntax to tag a specific commit is git tag <tagname> <commit-hash>.
Step 2: Match syntax with options
git tag v1.0 abc123 matches the correct order: tag name first, then commit hash. Others have wrong order or invalid flags.
Final Answer:
git tag v1.0 abc123 -> Option C
Quick Check:
git tag <tag> <commit> [OK]
Hint: Tag name comes before commit hash in command [OK]
Common Mistakes:
Swapping tag name and commit hash
Using git commit instead of git tag
Adding wrong flags like -m without message
3. What will be the output of git show v2.0 if v2.0 is a tag pointing to commit def456?
medium
A. Shows details of the commit with hash def456
B. Lists all tags in the repository
C. Deletes the tag v2.0
D. Shows the commit history of the current branch
Solution
Step 1: Understand git show with a tag
Running git show <tag> displays the commit details the tag points to.
Step 2: Match output with options
Shows details of the commit with hash def456 correctly describes the output. Other options describe different commands or actions.
Final Answer:
Shows details of the commit with hash def456 -> Option A
Quick Check:
git show tag = commit details [OK]
Hint: git show tag shows tagged commit info [OK]
Common Mistakes:
Thinking git show lists all tags
Confusing git show with git tag commands
Assuming git show deletes tags
4. You tried to tag a commit with git tag v1.1 abc789 but got an error saying "fatal: Not a valid object name abc789". What is the likely cause?
medium
A. The tag name v1.1 is already used
B. You forgot to push the tag to the remote
C. You need to add -m message to the tag command
D. The commit hash abc789 does not exist in the repository
Solution
Step 1: Analyze the error message
"Not a valid object name" means Git cannot find the commit hash specified.
Step 2: Check other options
Not pushing tags or tag name conflicts cause different errors. -m is optional for annotated tags.
Final Answer:
The commit hash abc789 does not exist in the repository -> Option D
Quick Check:
Invalid commit hash = error [OK]
Hint: Check commit hash exists before tagging [OK]
Common Mistakes:
Assuming tag name conflict causes this error
Thinking push is needed before tagging
Forcing -m message without need
5. You want to tag the commit that is two commits behind the current HEAD with the tag release-2024. Which command should you use?
hard
A. git tag release-2024 HEAD~2
B. git tag release-2024 HEAD^2
C. git tag release-2024 HEAD~
D. git tag release-2024 HEAD-2
Solution
Step 1: Understand commit references
In Git, HEAD~2 means two commits before HEAD. HEAD^2 means second parent of a merge commit, which is different.
Step 2: Match correct syntax for tagging
git tag release-2024 HEAD~2 correctly tags the commit two behind HEAD. Options C and D are invalid or incorrect references.
Final Answer:
git tag release-2024 HEAD~2 -> Option A
Quick Check:
HEAD~2 = two commits behind [OK]
Hint: Use HEAD~N to tag N commits behind HEAD [OK]
Common Mistakes:
Confusing HEAD~2 with HEAD^2
Using invalid commit references like HEAD~ or HEAD-2