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.
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?
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.
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?
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.
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?
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.
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?
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.
While performing an interactive rebase (git rebase -i), which keyword should you use to remove a commit completely from the branch's history?
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.