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 does the command git diff branch1 branch2 do?
It shows the differences between the files in branch1 and branch2. You can see what changes exist from one branch to the other.
Click to reveal answer
beginner
How can you see only the names of files that differ between two branches?
Use git diff --name-only branch1 branch2. This lists just the file names that have changes.
Click to reveal answer
intermediate
What is the difference between git diff branch1 branch2 and git diff branch2 branch1?
The output shows changes from the first branch to the second. So switching the order reverses the direction of the diff.
Click to reveal answer
beginner
Can git diff show changes between your current working directory and a branch?
Yes. Use git diff branch_name to see changes between your current files and that branch.
Click to reveal answer
beginner
What does the --stat option do with git diff?
It shows a summary of changes with file names and how many lines were added or removed, instead of full details.
Click to reveal answer
Which command shows the detailed differences between two branches?
Agit diff branch1 branch2
Bgit status
Cgit log
Dgit checkout branch1
✗ Incorrect
git diff branch1 branch2 shows the line-by-line differences between two branches.
How do you list only the files that differ between two branches?
Agit branch --list
Bgit diff --stat branch1 branch2
Cgit diff --name-only branch1 branch2
Dgit diff --cached
✗ Incorrect
The --name-only option lists just the file names that differ.
What happens if you swap the branch order in git diff branch1 branch2 to git diff branch2 branch1?
ANo difference in output
BThe diff output reverses, showing changes from branch2 to branch1
CIt merges the branches
DIt deletes branch1
✗ Incorrect
The diff direction reverses, showing changes from the first branch to the second.
Which command shows a summary of changes with line counts between branches?
Agit diff --name-only branch1 branch2
Bgit log --stat
Cgit diff --cached
Dgit diff --stat branch1 branch2
✗ Incorrect
--stat shows a summary with lines added and removed per file.
Can git diff branch_name show changes between your current files and a branch?
AYes
BNo
COnly if you commit first
DOnly if branches are merged
✗ Incorrect
This command compares your current working directory to the specified branch.
Explain how to use git diff to compare two branches and what the output means.
Think about comparing two versions of a document to see what changed.
You got /4 concepts.
Describe how to get a quick list of files that differ between two branches without full details.
Imagine checking which chapters changed without reading the whole text.
You got /4 concepts.
Practice
(1/5)
1. What does the command git diff branch1 branch2 show you?
easy
A. The commit history of branch1
B. The list of branches in the repository
C. The differences in code between branch1 and branch2
D. The status of files in the current branch
Solution
Step 1: Understand the purpose of git diff
The git diff command compares changes between two points in Git, such as branches.
Step 2: Identify what comparing two branches means
Comparing branch1 and branch2 shows the code differences between them.
Final Answer:
The differences in code between branch1 and branch2 -> Option C
Quick Check:
git diff branch1 branch2 = code differences [OK]
Hint: git diff between branches shows code changes [OK]
Common Mistakes:
Thinking it shows commit history
Confusing with git branch command
Expecting file status instead of differences
2. Which of the following is the correct syntax to see differences between two branches named main and feature?
easy
A. git diff main feature
B. git diff --branches main feature
C. git diff feature..main
D. git diff main..feature
Solution
Step 1: Recall git diff syntax for branches
The basic syntax is git diff branch1 branch2 without dots or extra flags.
Step 2: Evaluate each option
git diff main feature uses git diff main feature, which is correct. Options A and C use double dots which is incorrect for git diff. git diff --branches main feature uses a non-existent flag.
Final Answer:
git diff main feature -> Option A
Quick Check:
Correct syntax = git diff main feature [OK]
Hint: Use 'git diff branch1 branch2' without dots [OK]
Common Mistakes:
Using double dots '..' with git diff
Adding unsupported flags like --branches
Swapping branch order without reason
3. Given two branches, main and dev, where dev has added a new line console.log('Hello'); in app.js, what will git diff main dev show?
medium
A. An error message about branch names
B. A line removed: -console.log('Hello');
C. No output because branches are the same
D. A line added: +console.log('Hello');
Solution
Step 1: Understand what git diff shows for added lines
When a line is added in the second branch, git diff shows it with a plus sign (+).
Step 2: Apply to the example
The new line console.log('Hello'); added in dev will appear as a line starting with + in the diff output.
Final Answer:
A line added: +console.log('Hello'); -> Option D
Quick Check:
Added lines show with + in git diff [OK]
Hint: Added lines show with + in git diff output [OK]
Common Mistakes:
Thinking added lines show with -
Expecting no output for changes
Confusing branch order in diff
4. You run git diff main feature but get no output even though you know feature has changes. What is a likely reason?