What is the Difference Between Git Cherry-Pick and Git Revert?

git, git-cherry-pick, git-revert

Solution

`git cherry-pick` is like "Convert the specified commit into a patch and apply this patch here".

`git revert` is like "Convert the specified commit into a patch, 'invert' this patch (like in `patch -R`) and apply it here".

Both commands can lead to conflicts.

Cherry-pick is used on unmerged (not reachable by parent links from current commit) commits. Revert is typically used on merged commits.

Undoing a revert commit requires making another revert commit (leading to commit messages like "Revert of 'Revert of ...'"), not cherry-picking reverted commit (as it is considered already merged).

Problem

I still find the behavior of git revert somewhat confusing. After significant pain and misunderstanding, I learnt that git revert negates a particular commit rather than reverting to that commit. I have not used git cherry-pick so far. Can you elaborate on each of these two git commands? When and how do you prefer to use them?

Original source