As a programmer, each one of us has been in a situation where we want to pick a specific commit id from a different branch to the one you are currently working on. There is a very simple helpful git command that allows you to do this.
git cherry-pick <commit_sha>
You can check the logs and find the commit sha of the commit you want to write on your branch. Note that this commit forms the head of your current branch.
Let’s try to understand the effect using the following diagram. Assume that the following nodes demonstrate your commits into a certain repository.
We have two branches that branched out at
So, cherry-picking the
e commit will lead to the following effect.
--edit: This allows you to edit the commit message before writing the commit onto your working tree.
-x: This appends a line recording the original commit from where this commit is being cherry-picked. This option is useless if you are trying to cherry-pick from a private branch, and is only useful when the commit is being cherry-picked between two public branches. For example, this option can be super useful when trying to cherry-pick a commit between two maintenance branches.
--gpg-sign: Allows you to GPG sign the commit.
View all Courses