Wednesday, June 9, 2021

What is the use of cherry-pick command in git

 In Git, the cherry pick command takes changes from a target commit and places them on the HEAD of the currently checked out branch.

From here, you can either continue working with these changes in your working directory or you can immediately commit the changes onto the new branch.


Using the cherry-pick command

In the cherry-pick command's simplest form, you can just use the SHA identifier for the commit you want to integrate into your current HEAD branch.

To get the commit hash, you can use the git log command:

git log --oneline

Once you know the commit hash, you can use the cherry-pick command.

The syntax is:

git cherry-pick <commit sha>

For example:

git cherry-pick 65be1e5

This will dedicate the specified change to your currently checked-out branch.

If you'd like to make further modifications, you can also instruct Git to add commit changes to your working copy.

The syntax is:

git cherry-pick <commit sha> --no-commit

For example:

git cherry-pick 65be1e5 --no-commit

If you would like to select more than one commit simultaneously, add their commit hashes separated by a space:

git cherry-pick hash1 hash3

When cherry-picking commits, you can't use the git pull command because it fetches and automatically merges commits from one repository into another. 

Source 

https://www.gitkraken.com/learn/git/cherry-pick

https://opensource.com/article/21/4/cherry-picking-git

No comments:

Followers

Link