A command that can improve development efficiency: cherry-pick

Dear programmers and friends, I must have encountered such a situation: After working hard on the develop branch, I developed functional modules A, B, and C. At this time, the boss came and said, young people, we will now launch the function first. Module A, B. You must have 10,000 grass and mud horses running past in your heart, but in order to eat a meal, you have to act according to the boss's will.

How to do? One way is to rebuild a branch, and then roll back functional module C, leaving functional modules A and B. This approach is not bad, but there is a better way, that is, the cherry-pick function provided by git.

Cherry-pick is similar to a customized merge, which can pick off the commits on other branches one by one and merge them into the current branch.

Don't talk nonsense, just go to the example.

For example, I have a file ac, and I have completed three functional modules in the develop branch: feature A, feature B, and feature C. As shown below:

Now, the cheating boss only needs feature A and feature B. Now we use the cherry-pick command to directly merge the submissions of feature A and feature B into the master branch, as follows:

As you can see, feature A and feature B have been merged into the master branch. Please note that the commit hash value merged into the master branch has changed and is different from the original one.

It can be seen that the use of the cherry-pick command is very simple, namely:

git cherry-pick commitID

I just submitted cherry-pick one by one to the master branch, but what if there are 100 commits to be merged into the master branch? Can't do this one by one, right? Git also helped you think about it, it provides an interval operation method. Specifically, it's like this:

git cherry-pick commit1..commit100

But note 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 case, the above requirements can be implemented as follows:

Note: As mentioned above, the cherry-pick command will submit a new commit id every time a commit is selected. What if we want to postpone the submission of each commit after it is selected, and wait until all the commits are selected, and then commit manually by ourselves, what should we do? The answer is to use the -n option:

How, is it easy? Learned the cherry-pick command mother no longer has to worry about the boss's fever from time to time. Scan the QR code below and learn more git operations with Liang Xu!

 

The code word is not easy, if you find it helpful, please give a thumbs up before leaving~

-----------------

WeChat search for the public account [ Liang Xu Linux ], back-end reply keywords:

Guess you like

Origin blog.csdn.net/tjcwt2011/article/details/114117844