17. Cherry-pick copies a change, not a commit
Cherry-pick takes the difference a commit made against its parent, applies it on HEAD, and records a new commit with a new name; the original is untouched and unlinked.

17. Cherry-pick copies a change, not a commit

Cherry-pick takes the difference a commit made against its parent, applies it on HEAD, and records a new commit with a new name; the original is untouched and unlinked.

It is the building block of rebase and the reason "the same commit" can exist twice.

A commit on another branch has a fix you want. You could merge the whole branch. Or copy just that one change.

Cherry pick takes the difference that commit made, compared to its parent.

It applies that difference on top of your current commit. And records a new commit.

New parent, new content, new name. Same message, same author. It is a copy, not a move.

The original stays on its branch. Git does not know the two are related. You do.

Check yourself. After a cherry-pick, how many commits carry that change?

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Collaborators