Book Image

Git for Programmers

By : Jesse Liberty
Book Image

Git for Programmers

By: Jesse Liberty

Overview of this book

Whether you’re looking for a book to deepen your understanding of Git or a refresher, this book is the ultimate guide to Git. Git for Programmers comprehensively equips you with actionable insights on advanced Git concepts in an engaging and straightforward way. As you progress through the chapters, you’ll gain expertise (and confidence) on Git with lots of practical use cases. After a quick refresher on git history and installation, you’ll dive straight into the creation and cloning of your repository. You’ll explore Git places, branching, and GUIs to get familiar with the fundamentals. Then you’ll learn how to handle merge conflicts, rebase, amend, interactive rebase, and use the log, as well as explore important Git commands for managing your repository. The troubleshooting part of this Git book will include detailed instructions on how to bisect, blame, and several other problem handling techniques that will complete your newly acquired Git arsenal. By the end of this book, you’ll be using Git with confidence. Saving, sharing, managing files as well as undoing mistakes and basically rewriting history will be a breeze.
Table of Contents (16 chapters)
11
Finding a Broken Commit: Bisect and Blame
13
Next Steps
14
Other Books You May Enjoy
15
Index

Cherry-picking

Sometimes you just need one or a small number of commits from one branch to be added to the tip of another branch. A common case is this: you have a release branch and a feature branch. The release branch is "frozen" but then you need to add a commit from a feature branch to the release branch (possibly a patch to fix a problem). When you cherry-pick, the picked commit goes to the tip of the branch you are cherry-picking onto.

An illustration will help. Here's our starting point:

Figure 5.13: Before cherry-picking

We discover that we do not want all of Feature1 on Main, but we do want Feature1B (it has the fix or feature set we need). To do this at the command line you enter git cherry-pick a2cb5f3 where a2cb5f3 is the ID of the feature commit you want to cherry-pick.

What you end up with looks like this:

Figure 5.14: After the cherry-pick

Notice that Feature1B is now added to the tip of main, but it is also left on the...