Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the cherry-pick command

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to use the cherry-pick command". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the cherry-pick command.

Programmers friends must have encountered such a situation: in the develop branch of the hard work on the code after the development of the functional module A Magi B Magi C, then the boss said, young people, we now go online functional module AMagi B. You must have ten thousand grass-mud horses galloping past, but you have to do what your boss wants to do in order to make ends meet.

What shall I do? One way is to build a new branch, and then roll back the functional module C, leaving the functional module AMagi B. This is not impossible, but there is a better way, and that is the cherry-pick function provided by git.

Cherry-pick is similar to a customized merge, which can remove the commit from other branches one by one and merge them into the current branch.

Don't talk too much nonsense and go straight to the example.

For example, I now have a file a.c, and I have completed three functional modules in the develop branch: feature A _ Magi feature B ~ # feature C. As shown below:

Now, the boss who cheats only wants the feature AMagi feature B, and we now use the cherry-pick command to merge the submission of the feature A Magi feature B directly into the master branch, as follows:

As you can see, the functional module feature A focus feature B has been merged into the master branch. Notice that the commit hash value merged into the master branch has changed from the original.

As you can see, the cherry-pick command is easy to use, that is:

Git cherry-pick commitID

You just submitted cherry-pick to master branches one by one, but what if there are 100 commit to be merged into master branches? You can't operate one by one like this, can you? git also helps you think that it provides an interval operation method. Specifically, it goes like this:

Git cherry-pick commit1..commit100

Note, however, that this is a left-open and right-close operation, that is, commit1 will not be merged into the master branch, while commit100 will. In this way, the above requirements can be implemented as follows:

Note: as mentioned above, the cherry-pick command will submit and generate a new commit id for each commit selected. What if we want to postpone submission after each commit is picked, and wait until all the commit is selected, and then manually commit ourselves? The answer is with the-n option:

At this point, I believe you have a deeper understanding of "how to use the cherry-pick command". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report