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?
git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.
Besides being used for different tasks, the most significant difference is that git-cherry-pick changes the history of a branch, while git checkout is being used only to jump to a specific point in time (a specific commit) in the branch's history, without changing it.
A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.
With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With