>_ IzzyLab

Hands-on task

This task is step 8 of the course “Git: rewriting and rescuing history”

Transfer a single commit with cherry-pick

medium~5 min

In the repository /root/repo there's a branch feature with two commits: add other (file other.txt) and add hotfix (file hotfix.txt). The current branch is main. Transfer only the add hotfix commit into main without merging the whole branch: hotfix.txt must appear in main, but other.txt must not. Stay on the main branch.

What you'll practise:
  • git cherry-pick
  • transferring a commit
  • commit hash
  • branches

Topic breakdown

Sometimes from someone else's branch you need not a full merge but just one specific commit — for example, an urgent fix. git cherry-pick takes the commit specified by hash and applies its delta on top of the current branch, creating a new commit here with the same content but a different parent. It's important not to switch away from the target branch and to pass the hash of exactly the commit you need, finding it in the source's history.

What's checked

  1. current branch is main
  2. hotfix.txt transferred into main
  3. other.txt not in main

What it looks like