Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the pick command in git

Shulou Source: shulou.com Published: 2022-06-01 04:34:14 09月21日 Update

This article introduces the relevant knowledge of "how to use the pick command in git". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In git, pick is often used in conjunction with cherry, and the "cherry-pick" command is used to apply the specified commit to other branches with the syntax "git cherry-pick commitHash"; it also supports transferring multiple commits to the current branch at a time.

This article operating environment: Windows10 system, Git2.30.0 version, Dell G3 computer.

What is the use of pick in git

Git cherry-pick can select one or more commit (s) in a branch to operate (the object of the operation is commit). For example, suppose we have a stable version of the branch called v2.0, and another development version of the branch of v3.0, we can not directly merge the two branches, which will lead to stable version confusion, but want to add a v3.0 feature to v2.0, you can use cherry-pick here.

Is to resubmit the existing commit.

The purpose of the git cherry-pick command is to apply the specified commit to other branches.

$git cherry-pick

The above command applies the specified commit commitHash to the current branch. This will result in a new commit in the current branch, although their hashes will be different.

The method of use is as follows:

Git cherry-pick

The common configuration items for the git cherry-pick command are as follows.

(1)-ejiming Muyube edit

Open an external editor and edit the submission information.

(2)-njinghui murmuri commit

Only the workspace and staging areas are updated and no new submissions are generated.

(3)-x

Add a line (cherry picked from commit...) to the end of the submission message so that you can find out how the submission was made later.

(4)-s ~

Append the operator's signature at the end of the submission to indicate who did the operation.

(5)-m parent-number,--mainline parent-number

If the original commit is a merge node that comes from the merge of two branches, then Cherry pick will fail by default because it does not know which branch's code changes should be taken.

The-m configuration item tells Git which branch changes should be taken. Its parameter parent-number is an integer starting at 1 that represents the parent branch number of the original submission.

$git cherry-pick-m 1

The above command indicates that Cherry pick takes the change that commits commitHash from the parent branch of number 1.

Generally speaking, the first parent branch is the the branch being merged into that accepts the change, and the second parent branch is the the branch being merged from that serves as the source of the change.

That's all for the content of "how to use pick commands in git". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Branch command change information version application original one line two content that is more end knowledge configuration practical chaotic successful learning and then in general Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Shulou Tech Info Redmi Linux