Bird
0
0

You want to combine multiple commits on your feature branch into one before merging to main, but keep the branch history linear. Which approach fits best?

hard📝 Workflow Q9 of 15
Git - Rebasing
You want to combine multiple commits on your feature branch into one before merging to main, but keep the branch history linear. Which approach fits best?
AUse <code>git merge --squash feature</code> on main branch.
BUse <code>git rebase -i main</code> and squash commits interactively.
CDelete feature branch and create a new one.
DUse <code>git cherry-pick</code> for each commit.
Step-by-Step Solution
Solution:
  1. Step 1: Understand commit squashing

    Squashing combines multiple commits into one to simplify history.
  2. Step 2: Choose method preserving linear history

    Interactive rebase (git rebase -i) allows squashing commits on feature branch before merging.
  3. Final Answer:

    Use git rebase -i main and squash commits interactively. is correct.
  4. Quick Check:

    Squash commits with git rebase -i [OK]
Quick Trick: Squash commits with git rebase -i before merging [OK]
Common Mistakes:
  • Using merge --squash which creates a single commit but loses branch history
  • Deleting branches unnecessarily
  • Cherry-picking commits individually

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Git Quizzes