During a code review, you need to integrate the completed branch feature-login into the main branch of a shared Git repository. The team wants all of the branch's work-in-progress commits to appear on main as one commit so the history stays concise, but they must not rewrite the history of feature-login because it has already been shared. You are currently checked out on main. Which Git approach satisfies these requirements?
Run git merge --no-ff feature-login and push the resulting merge commit.
Run git merge --squash feature-login followed by git commit -m "Add login feature".
While on main, run git cherry-pick feature-login to copy the branch's changes.
Check out feature-login, run git rebase -i main to squash the commits, then merge the rewritten branch into main.
The git merge --squash <branch> command takes all commits from the specified branch, combines their changes, and stages them for a new commit on the current branch. It does not create a merge commit itself or alter the history of the source branch. A subsequent git commit command creates a single new commit, satisfying the requirement for a concise history.
git merge --no-ff <branch> creates an explicit merge commit, preserving all the individual commits from the feature branch in the history instead of collapsing them. An interactive rebase (git rebase -i) on the feature-login branch would rewrite that branch's public history, which the scenario explicitly forbids. Running git cherry-pick feature-login would only apply the single commit from the tip of the branch, not all of its commits, and would not squash them.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the `--squash` option in `git merge`?
Open an interactive chat with Bash
Why is it not recommended to use `git rebase -i` for shared branches?
Open an interactive chat with Bash
When should you use `--no-ff` in `git merge`?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access