0
0
Gitdevops~20 mins

git diff between branches - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Diff Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of git diff between two branches
What will be the output of the following command if branch feature has 3 new lines added to app.py compared to main?
Git
git diff main..feature -- app.py
AShows the commit history of <code>feature</code> branch
BShows all files changed between <code>main</code> and <code>feature</code> including <code>app.py</code>
CShows no output because <code>git diff</code> does not compare branches
DShows the 3 new lines added in <code>app.py</code> compared to <code>main</code>
Attempts:
2 left
💡 Hint
Use git diff branch1..branch2 to see differences between branches.
🧠 Conceptual
intermediate
1:30remaining
Understanding git diff branch range syntax
Which of the following correctly describes what git diff branchA..branchB shows?
AAll commits that exist in both branches
BChanges needed to convert <code>branchB</code> into <code>branchA</code>
CChanges needed to convert <code>branchA</code> into <code>branchB</code>
DThe list of files changed in <code>branchA</code> only
Attempts:
2 left
💡 Hint
Think about which branch is the base and which is the target.
Troubleshoot
advanced
2:00remaining
Why does git diff show no output between branches?
You run git diff main..feature but see no output, even though you expect differences. What could be a reason?
ABoth branches point to the same commit, so no differences exist
BYou forgot to add files to the staging area
CThe command only shows differences in the working directory, not between branches
DYou need to run <code>git fetch</code> before <code>git diff</code>
Attempts:
2 left
💡 Hint
Check if the branches have diverged commits.
🔀 Workflow
advanced
1:30remaining
Using git diff to review changes before merging
You want to review all changes in branch feature compared to main before merging. Which command is best?
Agit diff main..feature
Bgit diff feature..main
Cgit merge feature
Dgit log main..feature
Attempts:
2 left
💡 Hint
Think about which branch is the base and which is the feature.
Best Practice
expert
2:30remaining
Best practice for comparing branches with uncommitted changes
You have uncommitted changes in your working directory. You want to compare feature branch with main. What is the best practice?
AStash or commit your changes before running <code>git diff main..feature</code>
BRun <code>git diff main..feature</code> directly; uncommitted changes do not affect it
CUse <code>git diff --cached main..feature</code> to ignore uncommitted changes
DReset your working directory to discard uncommitted changes before diff
Attempts:
2 left
💡 Hint
git diff between branches compares branch tips and ignores working directory.