Video: Apply selected commits with cherry-pick
The video plays in YouTube’s player, in privacy-enhanced mode.
- 5 min video
- English narration · English and Arabic captions
- Watch on YouTube
Copy one teammate's fix onto your release branch without merging her whole branch, then check the new commit, its author, its files and what stayed behind.
Read the full lesson
The article has every step and command from the video, the practice exercise and the questions.
Video transcript
The narration of the video, cue by cue.
- Take one fix from another branch, and leave the rest.
- Cherry-pick copies the change one commit made, as a new commit here.
- The copy has a new ID, but keeps the author and the message.
- Build a baseline, Priya's branch with a note and a fix, and your release branch.
- Open the folder. The graph shows both branches from the same baseline.
- Priya's fix sits on top of an unrelated note. We want only the fix.
- Select the fix. One changed path: index.html.
- Make sure release label is current, and the work tree is clean.
- Right-click the fix, and choose Cherry-Pick Commit.
- There is no branch picker. It applies to the branch you are on.
- On the current commit itself, the command is disabled.
- Run it, and wait for the real result.
- A new commit sits on release label.
- Its ID differs from Priya's, because its parent is different.
- The author is still Priya. The committer is you.
- The page has the clarified label.
- The unrelated note did not come along. Your own note is still here.
- Priya's branch is exactly as it was.
- In the terminal, git log with a format shows the subject, author and committer.
- git diff-tree lists the paths this one commit changed.
- The status is empty. Nothing was left behind.
- With the x option, the message records where the pick came from.
- Pick the same commit again, and Git stops: the pick is empty.
- Change the input: the target has no signup form.
- The pick stops with a conflict. Resolve and continue, or abort.
- A change can depend on commits you did not take. Test the target.
- Abort puts the branch back. The source is never modified.
- Practice: report the new ID, author, committer and files.
- Next, set unfinished work aside safely with stash.