Advanced Git: Stashing, Cherry-Picking, and Rebasing Quiz Quiz

Explore your proficiency in advanced Git commands focused on stashing, cherry-picking, and rebasing. This quiz tests your understanding of practical scenarios, workflows, and important distinctions in modern version control.

  1. Stashing Uncommitted Changes

    Suppose you are halfway through implementing a feature but need to switch branches to review a bug fix. Which command safely saves your uncommitted changes for later retrieval without committing them?

    1. git add
    2. git hold
    3. git stash
    4. git merge

    Explanation: The correct answer is git stash, which temporarily saves your uncommitted modifications and cleans your working directory, allowing you to safely switch branches. git add stages changes for a commit but does not remove or hide them. git merge is for integrating histories of branches, while git hold is not a recognized Git command. Only git stash addresses the described scenario.

  2. Purpose of git cherry-pick

    In a scenario where you want to apply a single specific commit from one branch onto your current branch, which command is designed for this precise task?

    1. git cherry-pick
    2. git rebase -i
    3. git revert
    4. git checkout

    Explanation: git cherry-pick is the correct tool for applying individual commits from one branch onto another, preserving their changes. git checkout switches branches or restores files but doesn't transfer commits. git rebase -i allows interactive history rewriting but isn't made for targeting single non-sequential commits. git revert creates a reversal of commits, not an application of independent ones.

  3. Understanding Rebase Functionality

    If you have made several commits on a feature branch and want to place them on top of the latest main branch history to maintain a linear log, which Git command achieves this outcome?

    1. git pull --fast-forward
    2. git log --graph
    3. git rebase main
    4. git stash pop

    Explanation: The command git rebase main takes the commits from your current branch and re-applies them on top of main, maintaining a linear project history. git stash pop applies stashed changes but is unrelated to commit history. git pull --fast-forward updates your branch but does not specifically reapply commits in this manner. git log --graph visualizes commits and is not used for restructuring history.

  4. Handling Conflicts During Rebase

    During a rebase, you encounter a conflict in one of the files. After resolving the conflict, which command should you run to continue the rebase process?

    1. git rebase --continue
    2. git fixup
    3. git merge --continue
    4. git commit --resume

    Explanation: git rebase --continue is the correct command to resume the rebase after resolving conflicts. git commit --resume and git fixup are not valid Git commands. git merge --continue is used in merge conflicts but not in the context of rebase conflicts, making only git rebase --continue correct here.

  5. Dropping a Commit During Interactive Rebase

    While performing an interactive rebase (git rebase -i), which keyword should you use to remove a commit completely from the branch's history?

    1. reword
    2. fix
    3. merge
    4. drop

    Explanation: In an interactive rebase, using the drop keyword removes the selected commit from the branch's history. fix is not recognized as a rebase instruction; the correct keyword for combining is fixup. reword edits the commit message without removing the commit. merge is not an interactive rebase command. Only drop serves the purpose of eliminating a commit entirely.