Challenge - 5 Problems
Squash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this git command sequence?
You have 3 commits on your branch. You run
git rebase -i HEAD~3 and squash the last two commits into one. What will git log --oneline show after completing the rebase?Git
commit1: Initial commit
commit2: Added feature A
commit3: Fixed bug in feature AAttempts:
2 left
💡 Hint
Squashing merges commits into the previous one, combining their changes and messages.
✗ Incorrect
Squashing the last two commits into one means the first commit stays, and the second and third commits merge into one. So the log shows two commits: the original first commit and a combined commit of the last two.
❓ Troubleshoot
intermediate2:00remaining
Why does
git rebase -i HEAD~3 fail with 'cannot rebase: You have unstaged changes'?You try to squash commits using
git rebase -i HEAD~3 but get an error about unstaged changes. What is the cause?Attempts:
2 left
💡 Hint
Git requires a clean working directory to safely rebase.
✗ Incorrect
Git prevents rebasing when there are unstaged or uncommitted changes to avoid conflicts or data loss. You must commit or stash changes before rebasing.
❓ Configuration
advanced2:00remaining
How to configure git to always use squash when merging a feature branch?
You want to set up your git repository so that when you merge a feature branch into main, it always squashes commits automatically. Which configuration achieves this?
Attempts:
2 left
💡 Hint
Look for a setting related to merge and squash.
✗ Incorrect
Setting
merge.squash to true makes git merge commands squash commits by default.🔀 Workflow
advanced2:00remaining
What is the correct sequence to squash the last 4 commits into one with a new message?
You want to combine the last 4 commits into a single commit with a new commit message. Which sequence of commands is correct?
Attempts:
2 left
💡 Hint
Interactive rebase lets you choose which commits to squash.
✗ Incorrect
In interactive rebase, you keep the first commit as 'pick' and mark the rest as 'squash' to combine them into one commit with a new message.
✅ Best Practice
expert2:00remaining
What is the best practice when squashing commits before pushing to a shared remote branch?
You have squashed multiple commits locally and want to push to a shared remote branch. What should you do to avoid disrupting others?
Attempts:
2 left
💡 Hint
Force pushing can overwrite others' work.
✗ Incorrect
Force pushing to a shared branch can overwrite others' commits and cause problems. Creating a new branch preserves history and avoids conflicts.