Git a command to improve development efficiency: cherry pick


My friends must have encountered such a situation: after working hard on the development branch, we developed function modules a, B, C. at this time, the boss came to say, young man, we are going to launch function modules a and B first. You must have ten thousand grass mud horses galloping through your heart, but in order to make a living, you have to act according to the boss’s will.

What should I do? One way is to build a new branch, and then put function module C back, leaving function modules a and B. This is not a bad way, but there is a better way, that is, the cherry pick function provided by GIT.

Cherry pick is similar to a customized merge. It can take the commit from other branches one by one and merge them into the current branch.

Don’t talk much nonsense, just give examples.

For example, I now have a file A.C. I have completed three function modules in the development branch: feature a, feature B, and feature C. As shown in the figure below:

Git a command to improve development efficiency: cherry pick

Now, the boss of kengda only needs feature a and feature B. now we use the cherry pick command to merge the submission of feature a and feature B into the master branch, as follows:

Git a command to improve development efficiency: cherry pick

As you can see, feature a and feature B have been merged into the master branch. Note that the commit hash value merged into the master branch has changed from the original.

As you can see, the cherry pick command is very simple, that is:

git cherry-pick commitID

We just submitted cherry pick to the master branch one by one, but what if there are 100 commit to be merged into the master branch? Can’t you operate one by one? Git also helps you think of it. It provides an interval operation method. Specifically, it is as follows:

git cherry-pick commit1..commit100

Note, however, that this is a left open and right closed operation, that is, commit1 will not be merged into the master branch, while commit100 will. In this way, the above requirements can be realized by the following operations:

Git a command to improve development efficiency: cherry pick

Note: as mentioned above, the cherry pick command will submit every time a commit is picked and a new commit ID will be generated. What should we do if we want to postpone the submission of each commit after picking, and then manually commit after all the commit are picked? The answer is to use the – N option:

Git a command to improve development efficiency: cherry pick

Well, isn’t it easy? After learning the cherry pick command, my mother no longer had to worry about the boss’s hot head from time to time. Scan the QR code below quickly and learn more git operation together with Liangxu!

More interesting content, please pay attention to the official account.Xu Liang Linux, public response10245T technical data can be obtained free of charge, including:Linux, C / C + +, python, raspberry pie, embedded, Java, artificial intelligence, etc. Reply in official accountEntering a group, invite you to join the cloud technology exchange group.

Finally, a lot of friends have come to me recentlyLinux learning RoadmapBased on my own experience, I used my spare time to stay up late for a month and sorted out an e-book. Whether you are interview or self-improvement, I believe it will help you!

Free to everyone, just ask you to give me a compliment!

E-book | Linux development learning Roadmap

Also hope to have a small partner to join me, make this e-book more perfect!

What’s the gain? I hope the old fellow will take three strikes to show this article to more people.

Recommended reading: