nerdexam
CiscoCisco

200-901 · Question #560

200-901 Question #560: Real Exam Question with Answer & Explanation

To resolve conflicts and merge a feature branch into the remote master, the correct sequence involves aborting the initial merge attempt, preparing the feature branch by reverting the problematic commit, merging master into it, reapplying the changes, and finally merging the feat

Software Development and Design

Question

Drag and Drop Question Refer to the exhibit. Running the git merge example_branch command results in an error due to conflicts. The exhibit shows the output of the git log command on a branch named example_branch. Drag and drop the code from the bottom into the order to resolve the conflicts and merge example_branch into the remote master branch. Answer:

Explanation

To resolve conflicts and merge a feature branch into the remote master, the correct sequence involves aborting the initial merge attempt, preparing the feature branch by reverting the problematic commit, merging master into it, reapplying the changes, and finally merging the feature branch into master and pushing.

Approach. The core problem is an existing merge conflict when attempting to merge example_branch into master. The goal is to resolve this and push the changes. A common strategy for complex conflicts is to temporarily remove the conflicting changes from the feature branch, integrate the target branch's changes, then reintroduce the feature branch's changes while resolving conflicts, and finally perform a clean merge.

Here is the correct sequence and reasoning:

  1. git reset --hard && git checkout example_branch (step 1):

    • git reset --hard: When a merge fails, the repository is left in a conflicted state on the current branch (implicitly master because that's where git merge example_branch was run). This command aborts the failed merge attempt and resets the master branch to its state before the merge attempt, discarding all changes and restoring a clean working directory.
    • && git checkout example_branch: After master is cleaned, switch to example_branch. This allows us to work on the feature branch to prepare it for a clean merge.
  2. git revert ac40974fe8 && git merge master (step 2):

    • git revert ac40974fe8: Now on example_branch. The git log shows ac40974fe8 as the latest commit on example_branch. Assuming this commit is the primary source of conflict with master, git revert creates a new commit on example_branch that undoes the changes introduced by ac40974fe8. This temporarily removes the problematic changes, making example_branch 'less conflicting' for the next step.
    • && git merge master: After reverting the specific commit, merge master into example_branch. This brings all recent changes from master into example_branch, effectively updating example_branch with master's history. Since ac40974fe8's changes were reverted, this merge should encounter fewer (or no) conflicts related to that specific commit, allowing example_branch to be up-to-date with master.
  3. Reapply the change and run "git add -A && git commit" (step 3):

    • Since ac40974fe8 was reverted, its desired changes are no longer present in example_branch. This step involves manually re-adding or reconstructing those changes in the working directory of example_branch. During this reapplication, any conflicts with the newly merged master changes (from step 2) must be resolved manually. Once the changes are reapplied and conflicts resolved, git add -A stages all modifications, and git commit saves them as a new commit on example_branch. At this point, example_branch contains all desired changes, is fully up-to-date with master, and all conflicts are resolved within example_branch itself.
  4. git checkout master && git merge example_branch (step 4):

    • git checkout master: Switch back to the master branch.
    • && git merge example_branch: Now that example_branch has been fully updated with master's changes and has resolved its own changes against them, merging example_branch into master should be a clean operation, likely a fast-forward merge or a trivial merge commit, as all conflicts have already been handled.
  5. git push (step 5):

    • After the successful merge on the local master branch, this command pushes the updated master branch to the remote repository, completing the task.

Common mistakes.

  • common_mistake. One common mistake is to attempt to merge or push changes before conflicts are fully resolved or without preparing the branches correctly. For example:
  • Placing git checkout master && git merge example_branch early (e.g., as step 1 or 2): This command is precisely what led to the conflict, or it would re-introduce the conflict if the branches aren't prepared. It cannot be performed successfully until example_branch has been brought up-to-date with master and its own conflicting changes resolved.
  • Placing git push anywhere but the last step: git push is used to send local changes to the remote repository. It can only be done after all local commits and merges are complete and successful.
  • Using git revert ac40974fe8 && git merge master without first cleaning up the conflicted state on master and switching to example_branch: git revert operates on the currently checked-out branch. If still on master in a conflicted state, git revert wouldn't correctly target a commit on example_branch in a meaningful way to resolve the merge conflict, and git merge master would be merging master into itself or still be in a conflicted state, which is not productive for conflict resolution.

Concept tested. Git conflict resolution strategies, understanding Git merge workflow, git reset, git checkout, git revert, git merge, git add, git commit, and git push commands, and the ability to sequence these operations logically to achieve a desired state in a distributed version control system.

Reference. null

Topics

#Git#Merge Conflicts#Version Control#Remote Repository

Community Discussion

No community discussion yet for this question.

Full 200-901 PracticeBrowse All 200-901 Questions