Merge Conflicts and Safe History Rewriting Quiz Quiz

Test your knowledge of merge conflict resolution, interactive rebase, amending commits, cherry-pick/revert, and using reflog for safe history rewriting. This quiz helps you reinforce best practices in version control and managing your project's history safely and effectively.

  1. Identifying Merge Conflicts

    During a branch merge, you see conflict markers like u003Cu003Cu003Cu003Cu003Cu003Cu003C, =======, and u003Eu003Eu003Eu003Eu003Eu003Eu003E in one of your code files. What should you do next to resolve the conflict?

    1. Edit the file manually to fix conflicts and save changes
    2. Use 'revert' to automatically fix the problem
    3. Rename the branch to avoid the conflict
    4. Delete the conflicting file

    Explanation: When you encounter conflict markers, you should open the file, manually select or edit the conflicting sections, and save the resolved file. Using 'revert' does not solve merge conflicts; it undoes commits. Deleting the conflicting file is not recommended unless the entire file is unnecessary. Renaming the branch does not affect the file conflict itself.

  2. Purpose of Interactive Rebase

    What is the main purpose of using interactive rebase in version control?

    1. To merge two unrelated branches automatically
    2. To rewrite and organize commit history before merging
    3. To upload changes directly to a remote server
    4. To create a new branch from an older commit

    Explanation: Interactive rebase allows you to clean up, reorder, squash, or edit past commits, creating a tidy and meaningful history before integrating changes. It is not used for merging unrelated branches; that's handled by merge commands. Uploading changes uses push commands, not rebasing. Creating a new branch from an older commit can be done separately without interactive rebase.

  3. When to Use Amend

    If you just made a commit but forgot to include a minor file change, which action should you use to add that file to the latest commit safely?

    1. Force merge with the main branch
    2. Amend the latest commit
    3. Revert the latest commit
    4. Cherry-pick the latest commit

    Explanation: Amending modifies the most recent commit, letting you include the missing file without creating a new commit. Cherry-pick is used for copying commits between branches, not for editing existing ones. Reverting undoes changes but doesn't add new ones to the last commit. Force merging is not related to adding files to previous commits.

  4. Using Cherry-pick Safely

    In which scenario would you use cherry-pick safely in your project workflow?

    1. Resetting your branch to a previous commit
    2. Applying a specific commit from another branch to your current branch
    3. Automatically resolving all conflicts between branches
    4. Adding untracked files to the index

    Explanation: Cherry-pick is designed to apply individual commits from one branch to another, which is useful for selective changes. It does not resolve all conflicts; conflicts can still occur during cherry-pick. Adding untracked files is done with 'add', and resetting a branch is handled with 'reset' commands.

  5. Understanding the Reflog

    What is the primary purpose of the reflog in version control systems?

    1. To automatically resolve merge conflicts
    2. To permanently delete commits
    3. To track and recover recent changes to branch references
    4. To list all files changed in each commit

    Explanation: The reflog records updates to branch pointers, allowing you to recover commits lost by resets or amending. It does not resolve merge conflicts automatically or list specific file changes—that's done with log or diff commands. It does not permanently delete commits; instead, it helps you locate and restore them.

  6. Safe History Rewriting

    Which method is safest for rewriting local commit history before sharing with others?

    1. Directly editing the repository database
    2. Force-pushing immediately after every commit
    3. Interactive rebase on your local branch
    4. Using revert on all previous commits

    Explanation: An interactive rebase on a local branch lets you reorganize commits without affecting others until you push, making it safe and reviewable. Force-pushing after every commit is risky because it can overwrite collaborators' changes. Editing the repository database directly is unsafe and can easily corrupt the history. Reverting all commits creates unnecessary noise in the history.

  7. Resolving Conflicts with Tools

    When facing a complex merge conflict, which tool can help visualize and resolve differences between conflicting files?

    1. A syntax highlighter
    2. A file compression utility
    3. A backup restore application
    4. A graphical merge or diff tool

    Explanation: Graphical merge or diff tools provide visual comparison and conflict resolution options, making complex merges more straightforward. File compression utilities are for reducing file size, not resolving code conflicts. Syntax highlighters only color code for readability but do not handle merges. Backup restore tools are for recovering files in case of data loss, not for merging code.

  8. Difference Between Revert and Reset

    What is the key difference between using revert and reset on a commit?

    1. Revert creates a new commit to undo changes, while reset moves the branch pointer
    2. Revert merges two branches, while reset untracks files
    3. Revert deletes files permanently, while reset archives them
    4. Revert updates the reflog, while reset does not

    Explanation: Revert makes a new commit that undoes the changes introduced by a previous commit without deleting history. Reset moves the branch pointer to another commit, potentially erasing commits from branch history. Revert does not delete files permanently, perform merges, or specifically handle the reflog—though both update the reflog in their own way.

  9. Avoiding Problems When Amending

    Why is it not recommended to amend commits that have already been pushed to a shared repository?

    1. Because it deletes your local files
    2. Because it rewrites history and can cause confusion for others
    3. Because it automatically merges all branches
    4. Because it prevents you from making new branches

    Explanation: Amending a pushed commit changes its identity, causing conflicts for collaborators who have the old commit, making coordination difficult. It does not delete your local files, merge branches, or prevent future branch creation. Amending affects history integrity when working with shared repositories.

  10. Recovering Lost Commits

    After an accidental hard reset, how can you most easily recover commits that seem lost?

    1. Use the reflog to locate and restore the lost commits
    2. Compress the repository files
    3. Permanently delete the repository
    4. Merge with an unrelated branch

    Explanation: The reflog records recent updates to branch pointers, letting you find and recover commits lost by hard resets. Deleting the repository removes your data entirely. Compressing files doesn't affect commit history. Merging with an unrelated branch will not recover lost commits and can create further confusion.