Skip to content

Commit cd5dd7d

Browse files
committed
Use a better example for git cherry-pick
It is more common to cherry-pick select changes from feature branches into master than it is to do the other way around. Raymond Chen of "The Old New Thing" disagrees that there is any good use for cherry-pick and provides an alternate solution; his solution is given in the notes.
1 parent e2ff722 commit cd5dd7d

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

understanding-git.tex

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,35 +353,56 @@ \subsection{\gitcmd{cherry-pick}}
353353

354354
\begin{frame}
355355
\frametitle{Exercise}
356-
\goal{Cherry-pick \grefspec{D} into the current branch.}
357-
\defaultrepo
358-
\end{frame}
356+
The \gbranch{master} branch is currently checked out.
357+
Commit \grefspec{E} contains a useful change that you want to integrate right away.
359358

360-
\begin{frame}
361-
\frametitle{\gitcmd{cherry-pick D}}
362-
\framesubtitle{Create a new commit from the changes in \grefspec{D}.}
359+
\goal{Cherry-pick \grefspec{E} into the current branch.}
363360
\begin{figure}
364361
\centering
365362
\begin{tikzpicture}
366363
\gitDAG{
367364
A -- B -- {
368365
D,
369-
C -- E -- D$'$
366+
C -- E
370367
}
371368
};
372369
\gitbranch{master}
373370
{above=of D} {D}
374371
\gitbranch{topic}
375-
{above=of D$'$} {D$'$}
372+
{right=of E} {E}
376373
\gitHEAD
377-
{above=of topic} {topic}
374+
{left=of master} {master}
378375
\end{tikzpicture}
379376
\end{figure}
380-
A new commit, \grefspec{D$'$}, that contains the same changes as \grefspec{D} was added on top of \grefspec{E}. \gHEAD{} and \gbranch{topic} were advanced to \grefspec{D$'$}.
377+
\end{frame}
378+
379+
\begin{frame}
380+
\frametitle{\gitcmd{cherry-pick E}}
381+
\framesubtitle{Create a new commit from the changes in \grefspec{E}.}
382+
\begin{figure}
383+
\centering
384+
\begin{tikzpicture}
385+
\gitDAG{
386+
A -- B -- {
387+
D -- E$'$,
388+
C -- E
389+
}
390+
};
391+
\gitbranch{master}
392+
{above=of E$'$} {E$'$}
393+
\gitbranch{topic}
394+
{right=of E} {E}
395+
\gitHEAD
396+
{left=of master} {master}
397+
\end{tikzpicture}
398+
\end{figure}
399+
A new commit, \grefspec{E$'$}, that contains the same changes as \grefspec{E} was added on top of \grefspec{D}. \gHEAD{} and \gbranch{master} were advanced to \grefspec{E$'$}.
381400

382401
\note{
383-
This is a bad example because it would be better to do a \gitsubcmd{rebase} or a \gitsubcmd{merge} in this case,
384-
but it is one of the simplest examples.
402+
Cherry-picking may result in merge conflicts later on.
403+
Raymond Chen suggests using a merge-based strategy instead:
404+
405+
{\scriptsize\url{https://blogs.msdn.microsoft.com/oldnewthing/20180323-01/?p=98325}}
385406
}
386407
\end{frame}
387408

0 commit comments

Comments
 (0)