Book Image

Git Best Practices Guide

By : PIDOUX Eric
Book Image

Git Best Practices Guide

By: PIDOUX Eric

Overview of this book

Table of Contents (12 chapters)

Cherry-pick


This command lets you select a commit from a branch to apply it to another. The patch will be considered as a new commit in the selected branch.

Let's try to understand this by exploring the following example: Jim creates the jim branch from master and adds a new file in it:

Jim@local:~/webproject$ git checkout -b jim
Jim@local:~/webproject$ touch home.html
Jim@local:~/webproject$ git add home.html
Jim@local:~/webproject$ git commit -m 'add homepage'
Jim@local:~/webproject$ echo "<html>…</html>" > home.html
Jim@local:~/webproject$ git commit -a -m 'add content inside home'

As you can see, Jim creates the home.html file, adds it into Git, and commits it. Then he edits it and commits again. Now, let's see the commit history for this branch:

Jim@local:~/webproject$ git log --oneline
4f6ec45 add content inside home
22c45b7 add homepage

Now, Jim will apply the first commit to the master branch:

Jim@local:~/webproject$ git checkout master
Jim@local:~/webproject$ git cherry...