Bird
0
0

You have multiple commits in your feature branch but want to combine them into one clean commit before updating the PR. Which sequence of commands achieves this?

hard📝 Workflow Q15 of 15
Git - Collaboration Workflows
You have multiple commits in your feature branch but want to combine them into one clean commit before updating the PR. Which sequence of commands achieves this?
Agit merge main; git commit -m "Clean update"; git push
Bgit rebase -i main; edit commits; git push
Cgit reset --soft HEAD~3; git commit -m "Clean update"; git push --force
Dgit checkout main; git cherry-pick feature-branch; git push
Step-by-Step Solution
Solution:
  1. Step 1: Soft reset last 3 commits

    git reset --soft HEAD~3 moves HEAD back but keeps changes staged, allowing to combine commits.
  2. Step 2: Create a single new commit and force push

    Commit staged changes with a new message, then force push to update PR with one clean commit.
  3. Final Answer:

    git reset --soft HEAD~3; git commit -m "Clean update"; git push --force -> Option C
  4. Quick Check:

    Combine commits by soft reset and force push = B [OK]
Quick Trick: Use soft reset and force push to squash commits [OK]
Common Mistakes:
  • Using merge instead of squash
  • Forgetting to force push after rewriting history
  • Incorrectly rebasing without editing commits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Git Quizzes