Chapter 13. Miscellaneous
In this chapter, we cover some Git commands and topics that don’t fit easily into any of the foregoing discussions.
git cherry-pick
git cherry-pick allows you to apply the changeset of a given commit as a new commit on the current branch, preserving the original author information and commit message. As a very general rule, it’s best to avoid this in favor of factoring your work so that a commit appears in one place and is incorporated in multiple branches via merging instead, but that isn’t always possible or practical. Any arrangement of branches and merge discipline favors a certain flow of changes, and sometimes you need to buck that flow. For example, you might discover that a bug fix applied to a certain version actually needs to be applied to an earlier one as well, and merging in that direction is not desirable. Or, suppose you have your own repository for holding local changes made to your Unix distribution’s derivative of some open source project, such as Apache or OpenLDAP as modified and repackaged by Red Hat or Debian. If there is an upstream feature you need that the distribution does not provide (and they use Git), you can’t just merge it in, as your repository is not a clone of theirs—but you may be able to apply the relevant commits individually by cherry-picking.
The argument to git cherry-pick is a set of commits to apply, using the syntax described in Chapter 8. Some options:
-
--edit(-e) - Edit the commit message before committing.
-
-x
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access