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.
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?
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.
What is the main purpose of using interactive rebase in version control?
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.
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?
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.
In which scenario would you use cherry-pick safely in your project workflow?
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.
What is the primary purpose of the reflog in version control systems?
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.
Which method is safest for rewriting local commit history before sharing with others?
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.
When facing a complex merge conflict, which tool can help visualize and resolve differences between conflicting files?
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.
What is the key difference between using revert and reset on a commit?
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.
Why is it not recommended to amend commits that have already been pushed to a shared repository?
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.
After an accidental hard reset, how can you most easily recover commits that seem lost?
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.