How do you squash commits in Git?

How do you squash commits in Git?

a) By using git rebase -i (interactive rebase)
b) By using git squash
c) By using git commit --squash
d) By using git combine

Answer:

a) By using git rebase -i (interactive rebase)

Explanation:

To squash commits in Git, you use the git rebase -i (interactive rebase) command. Squashing commits combines multiple commits into a single one, simplifying the commit history.

During the rebase process, you can choose which commits to squash, which is useful for cleaning up your project history before merging it into the main branch.

This technique is often used to maintain a more concise and understandable commit history.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top