Back to roadmaps git Course

Precise Commit Merging and Reverting: cherry-pick and revert

Sometimes you need to copy a single commit from another branch, or safely undo a change that has already been pushed to production.


1. Merging Specific Commits with git cherry-pick

If you want to copy a single commit from a dev branch into your active branch without merging the entire branch history:

# Apply a specific commit using its hash ID
git cherry-pick commit_hash_id

If conflicts occur, Git will pause. Resolve the conflicts, stage the files, and run:

git cherry-pick --continue

2. Undoing Pushed Changes with git revert

[!WARNING] Do not use git reset to undo commits that have already been pushed to public remote branches.

Resetting rewrites commit history, which can disrupt your team's workflow. Instead, use git revert. This command creates a new "reversal" commit that applies the exact opposite changes of the target commit, keeping the project history intact:

# Generate a new commit that undoes the target commit's changes
git revert commit_hash_id

This approach is safe for team collaboration because it appends new history rather than rewriting past records.

Published on Last updated: