0
0
Gitdevops~20 mins

Squashing commits in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Squash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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 A
AOne commit with message of commit3 only
BTwo commits: first commit unchanged, second commit combines commit2 and commit3
COne commit with combined message of all three commits
DThree separate commits unchanged
Attempts:
2 left
💡 Hint
Squashing merges commits into the previous one, combining their changes and messages.
Troubleshoot
intermediate
2: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?
AYour repository is corrupted and needs repair
BYou are on the wrong branch and must switch to master first
CYou have uncommitted changes in your working directory that must be committed or stashed before rebasing
DYou need to update git to the latest version
Attempts:
2 left
💡 Hint
Git requires a clean working directory to safely rebase.
Configuration
advanced
2: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?
Agit config --global merge.squash true
Bgit config --global pull.rebase squash
Cgit config --global merge.ff false
Dgit config --global merge.squash false
Attempts:
2 left
💡 Hint
Look for a setting related to merge and squash.
🔀 Workflow
advanced
2: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?
Agit rebase -i HEAD~4; mark first commit as 'pick' and others as 'squash'; save and exit
Bgit rebase -i HEAD~4; mark all commits as 'pick'; save and exit
Cgit merge --squash HEAD~4; git commit -m "New combined message"
Dgit reset --soft HEAD~4; git commit -m "New combined message"
Attempts:
2 left
💡 Hint
Interactive rebase lets you choose which commits to squash.
Best Practice
expert
2: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?
AForce push with <code>git push --force</code> after squashing
BPush normally with <code>git push</code> without force
CDelete the remote branch and push again
DCreate a new branch and push the squashed commits there
Attempts:
2 left
💡 Hint
Force pushing can overwrite others' work.