Explore key concepts of git cherry-pick, including use cases, common pitfalls, command syntax, and handling conflicts. Enhance your understanding of selective commit integration and best practices in team workflows with this quiz on Git’s cherry-pick functionality.
What does the git cherry-pick command do when used on a specific commit in your repository?
Explanation: The git cherry-pick command applies the changes from a specific commit onto your current working branch, creating a new commit with those changes. It does not merge everything from another branch, as merge does that. Cherry-pick does not undo or revert commits; revert is the command for that. It also does not delete commits; remove or filter-branch would be used for such history rewriting.
In which scenario is it most appropriate to use git cherry-pick instead of a merge or rebase?
Explanation: Cherry-pick is ideal for applying individual commits selectively, such as pulling in a bug fix from a feature branch without merging all its changes. For combining all changes, merge or rebase is more suitable. To undo a commit, revert should be used. Cherry-pick is not primarily a conflict resolution tool for multiple branches; rather, it may itself introduce conflicts that need to be resolved.
Given the commit hash abc12345, which is the correct command to cherry-pick this commit onto your current branch?
Explanation: The correct syntax is git cherry-pick followed by the commit hash. The command git pick does not exist, making it an incorrect option. git branch-pick is not a valid command either, and git cherry is used for different purposes, such as comparing branches for unique commits rather than applying them.
What should you do if you encounter a merge conflict while running git cherry-pick on a commit?
Explanation: When a conflict occurs during cherry-pick, you need to manually resolve the conflicting files and then use git cherry-pick --continue to complete the process. Deleting files will result in data loss and is not a proper conflict resolution technique. Simply closing the terminal does not abort or resolve the operation. Ignoring the conflict and proceeding is not possible; unresolved conflicts block further progress.
What is a potential risk of using git cherry-pick extensively between long-lived branches?
Explanation: Frequent use of cherry-pick across long-lived branches can lead to duplicate changes and make merges harder due to repeated commits appearing in multiple places. It does not hide the commit history; commit logs remain visible. Cherry-picking does not affect tags or delete them. The command does not automatically overwrite remotes; it only affects your local branch until you push changes.