history
git cherry-pick
Applies the changes from one or more specific commits onto the current branch as new commits. Useful for porting bug fixes across branches.
git cherry-pick [<options>] <commit>... Common flags
| Flag | Purpose |
|---|---|
| -x | Append a 'cherry picked from' line to the message |
| -n / --no-commit | Apply changes without auto-committing |
| --continue | Resume after resolving conflicts |
| --abort | Cancel the cherry-pick and restore prior state |
| -e / --edit | Edit the commit message before recording |
| -m <parent> | Cherry-pick a merge commit relative to given parent |
Examples
git cherry-pick abc123 Apply commit abc123 onto the current branch
git cherry-pick abc123..def456 Pick a range of commits (exclusive of abc123)
git cherry-pick -x hotfix~1 Backport a fix with an attribution line
Gotcha
Cherry-picking creates a new commit with a different SHA; picking the same fix onto multiple branches can duplicate history if later merged.
Related commands
git rebase
Replays commits from your branch on top of another base, producing a linear history without merge commits. Powerful for cleaning up history before pushing.
git revert
Creates a new commit that inverts the changes of a previous commit, preserving history. The safe way to undo pushed commits on shared branches.
git merge
Joins the history of another branch into the current one, creating a merge commit when histories diverge. Preserves the full branching topology.
git log
Displays commit history in reverse chronological order with filters for author, date, path, or content. The primary tool for exploring project history.
git tag
Marks specific commits with a permanent name, typically for release versions like v1.2.0. Supports lightweight tags (a ref) or annotated tags (a full object with metadata).