Two small, frequently useful commands for handling commits individually, rather than through a full merge or rebase.
Applies a single commit from anywhere in the project's history onto the current branch — useful when exactly one fix or change is needed from another branch, not everything on it.
git switch main
git cherry-pick a1b2c3d
# Applies commit a1b2c3d's exact changes as a new commit on mainA real use: a bug fix committed on a feature branch also needs to go out immediately on main, without merging the feature branch's unfinished work along with it.
Just like a merge, a cherry-pick can conflict if the target branch has diverged too much — resolved exactly the same way as the earlier Merge Conflicts lesson: edit the file, remove the markers, then continue.
# After resolving conflict markers in the affected files:
git add .
git cherry-pick --continue
# Or abandon the cherry-pick entirely:
git cherry-pick --abortRather than creating a new commit for a typo or a forgotten file, --amend folds a change into the most recent commit instead.
# Fix just the commit message
git commit --amend -m "Corrected commit message"
# Add a forgotten file to the last commit, keeping the same message
git add forgotten-file.txt
git commit --amend --no-editThe same shared-history rule applies here
--amend rewrites the last commit entirely — it gets a new hash. Exactly the same rule as reset and rebase from earlier lessons: never amend a commit that's already been pushed and possibly pulled by someone else.
| Command | Use for |
|---|---|
| git cherry-pick | Copying one specific commit onto the current branch |
| git commit --amend | Fixing the message or contents of the most recent, not-yet-shared commit |