commit_graph.tex 25.2 KB
Newer Older
Mihai's avatar
Mihai committed
1 2 3 4 5 6 7 8
\documentclass[slidestop]{beamer}

\usepackage{framed}

\input{../shared/shared.tex}

\author{Mihai Lefter}
\title{\courseTitle}
9
\providecommand{\mySubTitle}{The git commit graph}
Mihai's avatar
Mihai committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
\providecommand{\myConference}{\courseTitle}
\providecommand{\myGroup}{}
\providecommand{\myDepartment}{Department of Human Genetics}
\providecommand{\myCenter}{Center for Human and Clinical Genetics}

\definecolor{cblack}{rgb}{0,0,0}
\definecolor{cwhite}{rgb}{1,1,1}
\definecolor{command-color}{rgb}{0,0.5,0}
\definecolor{git-color}{rgb}{0.94,0.23,0.18}
\definecolor{option-color}{rgb}{0.9,0.2,0.11}
\definecolor{argument-color}{rgb}{0.11,0.27,0.7}
\definecolor{pattern-color}{rgb}{0,0.5,0.5}
\definecolor{wildcard-color}{rgb}{0.75,0.3,0}
\definecolor{cli-text}{rgb}{0.15,0.15,0.15}
\definecolor{important-note}{rgb}{0.69,0.13,0.13}
\definecolor{redirection}{rgb}{0.99,0.13,0.13}
\definecolor{shadecolor}{rgb}{0.9,0.9,0.9}
\definecolor{one-dot}{rgb}{0.9,0.2,0.0}
\definecolor{two-dots}{rgb}{0.11,0.11,0.8}
\definecolor{slash}{rgb}{0.3,0.3,0.3}

\definecolor{head}{HTML}{B22222}
\definecolor{branch}{HTML}{20b2aa}
\definecolor{commit-id}{HTML}{b8860b}

\usetheme{lumc}

\lstset{ %
  basicstyle=\ttfamily,
  language=none,
  frame=none,
  numbers=none,
  numbersep=0,
  keepspaces=true,
  stringstyle=\color{cli-text},
  keywordstyle=\color{cli-text},
  commentstyle=\color{cli-text}
}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Table of contents}
    \tableofcontents[currentsection, subsectionstyle=hide/hide]
  \end{frame}
}

\begin{document}

% This disables the \pause command, handy in the editing phase.
%\renewcommand{\pause}{}

% Make the title page.
\makeTitleSlide{\includegraphics[width=3.5cm]{../shared/git_logo.pdf}}

65
\section{The git commit graph}
Mihai's avatar
Mihai committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
\subsection{A linear history}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_00.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_01.pdf}
 \end{center}
\end{pframe}

\subsection{The default \lstinline{master} branch}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_02.pdf}
 \end{center}
\end{pframe}

\subsection{The \lstinline{HEAD} pointer}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_03.pdf}
 \end{center}
\end{pframe}

\subsection{Committing}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_04.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_05.pdf}
 \end{center}
\end{pframe}

\subsection{A non-linear history}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_06.pdf}
 \end{center}
\end{pframe}

\subsection{Use branches to keep track of different code paths}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_07.pdf}
 \end{center}
\end{pframe}

\subsection{Merging}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/commit_graph/commit_graph_08.pdf}
 \end{center}
\end{pframe}

\section{Inspecting the commit graph}
\subsection{An example repository}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/inspect_commit_graph/inspect_commit_graph_00.pdf}
 \end{center}
\end{pframe}

\subsection{Showing the current branch}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
139
    \lstinline{On branch} \textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
140 141 142 143 144 145 146 147 148 149 150 151
    \lstinline{nothing to commit, working directory clean.}
  \end{framed}

  Remember: you cannot type \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}} enough!
\end{pframe}

\subsection{Listing branches}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}}\\
    \lstinline{  interface}\\
    \lstinline{  license}\\
152
    \lstinline{* }\textcolor{branch}{\lstinline{master}}
Mihai's avatar
Mihai committed
153 154 155
  \end{framed}
  \vspace{-0.3cm}

156
  Three branches, current branch is  \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
157 158 159 160 161
  \pause
  \vspace{-0.3cm}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}} \textcolor{argument-color}{\lstinline{-v}}\\
162 163 164
    \lstinline{  interface }\textcolor{commit-id}{\lstinline{8fc25c1}}\lstinline{ Trivial Python interface}\\
    \lstinline{  license   }\textcolor{commit-id}{\lstinline{0fbe3e3}}\lstinline{ Add MIT license}\\
    \lstinline{* }\textcolor{branch}{\lstinline{master}}\lstinline{    }\textcolor{commit-id}{\lstinline{c7f3bd9}}\lstinline{ Add .gitignore file}
Mihai's avatar
Mihai committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  \end{framed}
  \vspace{-0.3cm}

  \textcolor{argument-color}{\lstinline{-v}}: Shows the commit each branch points to.
\end{pframe}

\subsection{The commit log}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{log}}
    \textcolor{argument-color}{\lstinline{--oneline --decorate}}\\
    \textcolor{commit-id}{\lstinline{c7f3bd9}} \lstinline{(}\textcolor{head}{\lstinline{HEAD}} \lstinline{->} \textcolor{branch}{\lstinline{master}}\lstinline{) Add .gitignore file}\\
    \textcolor{commit-id}{\lstinline{4a44c4e}} \lstinline{Merge branch 'license'}\\
    \textcolor{commit-id}{\lstinline{64af1ee}} \lstinline{Add course teachers to README}\\
    \textcolor{commit-id}{\lstinline{0fbe3e3}} \lstinline{(}\textcolor{branch}{\lstinline{license}}\lstinline{) Add MIT license}\\
    \textcolor{commit-id}{\lstinline{d1c7fd7}} \lstinline{Initial commit with README}
  \end{framed}

  \textcolor{argument-color}{\lstinline{--oneline}}: Shows commit summary on one line.

  \textcolor{argument-color}{\lstinline{--decorate}}: Adds branch information.
\end{pframe}

\subsection{The commit log as a graph}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{log}}
    \textcolor{argument-color}{\lstinline{--oneline --decorate --graph --all}}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{8fc25c1}} \lstinline{(}\textcolor{branch}{\lstinline{interface}}\lstinline{) Trivial Python interface}\\
    \lstinline{| *} \textcolor{commit-id}{\lstinline{c7f3bd9}} \lstinline{(}\textcolor{head}{\lstinline{HEAD}} \lstinline{->} \textcolor{branch}{\lstinline{master)}} \lstinline{Add .gitignore file}\\
    \lstinline{|/}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{4a44c4e}} \lstinline{Merge branch 'license'}\\
Mihai's avatar
Mihai committed
197
    \lstinline{|\}\\
Mihai's avatar
Mihai committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    \lstinline{| *} \textcolor{commit-id}{\lstinline{0fbe3e3}} \lstinline{(}\textcolor{branch}{\lstinline{license}}\lstinline{) Add MIT license}\\
    \lstinline{* |} \textcolor{commit-id}{\lstinline{64af1ee}} \lstinline{Add course teachers to README}\\
    \lstinline{|/}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{d1c7fd7}} \lstinline{Initial commit with README}
  \end{framed}
  \vspace{-0.2cm}

  \textcolor{argument-color}{\lstinline{--graph}}: Shows the commit graph.

  \textcolor{argument-color}{\lstinline{--all}}: Includes all branches instead of just the current one.
\end{pframe}

\section{Navigating the commit graph}

\subsection{Switching to another branch}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}} \textcolor{argument-color}{\lstinline{interface}}\\
216
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{interface}}\lstinline{'}
Mihai's avatar
Mihai committed
217 218 219
  \end{framed}
  \vspace{-0.2cm}
  \begin{itemize}
220
   \item Points \textcolor{head}{\lstinline{HEAD}} to the named branch.
Mihai's avatar
Mihai committed
221 222 223 224 225 226
   \item Updates your working directory.
  \end{itemize}
  \pause

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
227
    \lstinline{On branch }\textcolor{branch}{\lstinline{interface}}\\
Mihai's avatar
Mihai committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    \lstinline{nothing to commit, working directory clean.}
  \end{framed}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/graph_navigation/graph_navigation_00.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/graph_navigation/graph_navigation_01.pdf}
 \end{center}
\end{pframe}

\subsection{Detached \lstinline{HEAD} state}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}} \textcolor{argument-color}{\lstinline{4a44c4e}}\\
248 249
    \lstinline{Note: checking out '}\textcolor{commit-id}{\lstinline{4a44c4e}}\lstinline{'.}\\ \\
    \lstinline{You are in }\textcolor{red}{\lstinline{'detached HEAD'}}\lstinline{ state. You can look ...}\\ \\
Mihai's avatar
Mihai committed
250 251 252 253 254 255 256 257
%     \lstinline{around, make experimental changes and commit them,}\\
%     \lstinline{and you can discard any commits you make in this}\\
%     \lstinline{state without impacting any branches by performing}\\
%     \lstinline{another checkout.}\\ \\
    \lstinline{If you want to create a new branch to retain}\\
    \lstinline{commits you create, you may do so (now or later) by}\\
    \lstinline{using -b with the checkout command again. Example:}\\ \\
    \lstinline{  git checkout -b <new-branch-name>}\\ \\
258
    \textcolor{head}{\lstinline{HEAD}}\lstinline{ is now at }\textcolor{commit-id}{\lstinline{4a44c4e}}\lstinline{... Merge Branch 'license'}
Mihai's avatar
Mihai committed
259 260 261 262 263 264
  \end{framed}
\end{pframe}

\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
265
    \textcolor{red}{\lstinline{HEAD detached at}}\lstinline{ }\textcolor{commit-id}{\lstinline{4a44c4e}}\\
Mihai's avatar
Mihai committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
    \lstinline{nothing to commit, working directory clean.}
  \end{framed}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/graph_navigation/graph_navigation_02.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/graph_navigation/graph_navigation_03.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/graph_navigation/graph_navigation_04.pdf}
 \end{center}
\end{pframe}

\section{Manipulating the commit graph}

\subsection{Creating a new branch}
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}} \textcolor{argument-color}{\lstinline{lib}}
  \end{framed}
  \vspace{-0.2cm}

297
  Creates branch \textcolor{branch}{\lstinline{lib}} at \textcolor{head}{\lstinline{HEAD}}.
Mihai's avatar
Mihai committed
298 299 300
  \pause
  \medskip
  
301
  How can I see that it worked?
Mihai's avatar
Mihai committed
302 303 304 305 306 307 308 309
  \pause
  \vspace{-0.3cm}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}}\\
    \lstinline{  interface}\\
    \lstinline{  lib}\\
    \lstinline{  license}\\
310
    \lstinline{* }\textcolor{branch}{\lstinline{master}}
Mihai's avatar
Mihai committed
311 312 313 314
  \end{framed}
  \vspace{-0.2cm}
  \pause
  
315
  How can I switch to the new \textcolor{branch}{\lstinline{lib}} branch?
Mihai's avatar
Mihai committed
316 317 318 319 320
\end{pframe}
  
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}} \textcolor{argument-color}{\lstinline{lib}}\\
321
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{lib}}\lstinline{'}
Mihai's avatar
Mihai committed
322 323 324 325 326 327 328 329
  \end{framed}
\end{pframe}
  
\begin{pframe}
  For Git pro's, in one command:
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout -b}}
    \textcolor{argument-color}{\lstinline{lib}} \\
330
    \lstinline{Switched to a new branch '}\textcolor{branch}{\lstinline{lib}}\lstinline{'}
Mihai's avatar
Mihai committed
331 332
  \end{framed}

333 334
  At this point, \textcolor{branch}{\lstinline{lib}} is just a label to the same commit as
  \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_00.pdf}
 \end{center}
\end{pframe}

\subsection{Working on a branch}
\begin{pframe}
  We can extend the \lstinline{lib} branch by adding commits.
  \vspace{-0.4cm}
  \begin{framed}
    \lstinline{$} \lstinline{echo 'VERSION=1' > testlib.py}\\
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{add}}
    \textcolor{argument-color}{\lstinline{testlib.py}} \\
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{commit -m}}
    \textcolor{argument-color}{\lstinline{'Add empty testlib'}}
  \end{framed}
  \pause
  \vspace{-0.5cm}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{log}}
    \textcolor{argument-color}{\lstinline{--oneline --decorate --graph --all}}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{251a51b}} \lstinline{(}\textcolor{head}{\lstinline{HEAD}} \lstinline{->} \textcolor{branch}{\lstinline{lib}}\lstinline{) Add empty testlib}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{c7f3bd9}} \lstinline{(}\textcolor{branch}{\lstinline{master}} \lstinline{) Add .gitignore file}\\
    \lstinline{| *} \textcolor{commit-id}{\lstinline{8fc25c1}} \lstinline{(}\textcolor{branch}{\lstinline{interface}}\lstinline{) Trivial Python interface}\\
    \lstinline{|/}\\
    \lstinline{*} \textcolor{commit-id}{\lstinline{4a44c4e}} \lstinline{Merge branch 'license'}\\
    \lstinline{...}
%     \lstinline{|\\}\\
%     \lstinline{| *} \textcolor{commit-id}{\lstinline{0fbe3e3}} \lstinline{(}\textcolor{branch}{\lstinline{license}}\lstinline{) Add MIT license}\\
%     \lstinline{* |} \textcolor{commit-id}{\lstinline{64af1ee}} \lstinline{Add course teachers to README}\\
%     \lstinline{|/}\\
%     \lstinline{*} \textcolor{commit-id}{\lstinline{d1c7fd7}} \lstinline{Initial commit with README}
  \end{framed}
\end{pframe}

\subsection{Extended \lstinline{lib} branch}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_01.pdf}
 \end{center}
\end{pframe}

\subsection{Fast forward merging}
\begin{pframe}
383
  Let's merge our work on \textcolor{branch}{\lstinline{lib}} back into \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
384 385 386
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}}
    \textcolor{argument-color}{\lstinline{master}} \\
387
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{master}}\lstinline{'}\\
Mihai's avatar
Mihai committed
388 389
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
    \textcolor{argument-color}{\lstinline{lib}}\\
390
    \lstinline{Updating }\textcolor{commit-id}{\lstinline{c7f3bd9}}\lstinline{..}\textcolor{commit-id}{\lstinline{251a51b}}\\
Mihai's avatar
Mihai committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
    \lstinline{Fast-forward}\\
    \lstinline{ testlib.py |    1 +}\\
    \lstinline{ 1 file changed, 1 insertion(+)}\\
    \lstinline{ create mode 100644 testlib.py}
  \end{framed}
\end{pframe}

\subsection{Merged branch \lstinline{lib} into \lstinline{master} (fast forward).}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_02.pdf}
 \end{center}
\end{pframe}

\subsection{Three-way merging}
\begin{pframe}
407
  Let's merge our work on \textcolor{branch}{\lstinline{interface}} back into \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
408 409 410 411 412 413 414 415 416 417 418 419
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
    \textcolor{argument-color}{\lstinline{interface}}\\
    \lstinline{Merge made by the 'recursive' strategy.}\\
    \lstinline{ interface.py |    3 +++}\\
    \lstinline{ 1 file changed, 3 insertions(+)}\\
    \lstinline{ create mode 100755 interface.py}
  \end{framed}
  \vspace{-0.2cm}

  This merge was harder:
  \begin{itemize}
420 421 422
    \item \textcolor{branch}{\lstinline{interface}} and \textcolor{branch}{\lstinline{master}} had diverged.
    \item Git determines changes in \textcolor{branch}{\lstinline{interface}} and \textcolor{branch}{\lstinline{master}}
    since their most recent common ancestor.
Mihai's avatar
Mihai committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    \item A new commit is created.
  \end{itemize}
\end{pframe}

\subsection{Merged branch \lstinline{interface} into \lstinline{master}}
\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_03.pdf}
 \end{center}
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_04.pdf}
 \end{center}
\end{pframe}

\subsection{Deleting branches}
\begin{pframe}
  Old branches that have been merged can be deleted.
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch -d}}
    \textcolor{argument-color}{\lstinline{interface}}\\
446
    \lstinline{Deleted branch }\textcolor{branch}{\lstinline{interface}}\lstinline{ (was }\textcolor{commit-id}{{8fc25c1}}\lstinline{).}
Mihai's avatar
Mihai committed
447 448 449 450 451
  \end{framed}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch -d}}
    \textcolor{argument-color}{\lstinline{lib license}}\\
452 453
    \lstinline{Deleted branch }\textcolor{branch}{\lstinline{lib}}\lstinline{ (was }\textcolor{commit-id}{\lstinline{251a51b}}\lstinline{).}\\
    \lstinline{Deleted branch }\textcolor{branch}{\lstinline{license}}\lstinline{ (was }\textcolor{commit-id}{\lstinline{0fbe3e3}}\lstinline{).}
Mihai's avatar
Mihai committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
  \end{framed}

  No history is lost, just labels removed.
\end{pframe}

\begin{pframe}
 \begin{center}
   \includegraphics[width=\textwidth]{images/branching/branching_05.pdf}
 \end{center}
\end{pframe}

\section{Basic merge conflicts}

\subsection{Merge conflicts}
\begin{pframe}
  Git is pretty good at merging:
  \begin{itemize}
    \item The changes might have been in different files.
    \item Or in different parts of the same file.
    \item Git tries to figure out a sensible result.
  \end{itemize}
  \bigskip
  \pause

  Sometimes this is not possible:
  \begin{itemize}
    \item The changes might be incompatible.
    \item When we try \lstinline{git merge}, Git gives up.
    \item This situation is called a {\em merge conflict}.
  \end{itemize}
\end{pframe}

\subsection{Setting the stage (1/3)}
\begin{pframe}
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{log}}
   \textcolor{argument-color}{\lstinline{--oneline --decorate --graph --all}}\\
491 492
   \lstinline{* }\textcolor{commit-id}{\lstinline{5edaf08}}\lstinline{ (}\textcolor{branch}{\lstinline{hue}}\lstinline{) State character ...}\\
   \lstinline{| * }\textcolor{commit-id}{\lstinline{f1ef19c}}\lstinline{ (}\textcolor{head}{\lstinline{HEAD}}\lstinline{, }\textcolor{branch}{\lstinline{master}}\lstinline{) State character ...}\\
Mihai's avatar
Mihai committed
493
   \lstinline{|/}\\
494
   \lstinline{* }\textcolor{commit-id}{\lstinline{1f6d2ab}}\lstinline{ Initial commit} 
Mihai's avatar
Mihai committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
  \end{framed}

  We'd like to merge branch \lstinline{hue} into \lstinline{master}.
\end{pframe}

\subsection{Setting the stage (2/3)}
\begin{pframe}
 The last commit on \lstinline{master}:
 \vspace{-0.3cm}
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{show}}\\
   \lstinline{f1ef19c State character preference}\\
   \lstinline{diff --git a/FACTS.md b/FACTS.md}\\
   \lstinline{index de15194..ef40359 100644}\\
   \lstinline{--- a/FACTS.md}\\
   \lstinline{+++ b/FACTS.md}\\
   \lstinline{@@ -1,2 +1,4 @@}\\
   \lstinline{ Facts about television series}\\
   \lstinline{ =============================}\\
   \lstinline{+}\\
   \lstinline{+My favorite character is Eric Cartman.}
  \end{framed}
\end{pframe}

\subsection{Setting the stage (3/3)}
\begin{pframe}
 The last commit on \lstinline{hue}:
 \vspace{-0.3cm}
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{show}}
   \textcolor{argument-color}{\lstinline{--oneline}} \textcolor{argument-color}{\lstinline{hue}}\\
   \lstinline{5edaf08 State character preference}\\
   \lstinline{diff --git a/FACTS.md b/FACTS.md}\\
   \lstinline{index de15194..5e69508 100644}\\
   \lstinline{--- a/FACTS.md}\\
   \lstinline{+++ b/FACTS.md}\\
   \lstinline{@@ -1,2 +1,4 @@}\\
   \lstinline{ Facts about television series}\\
   \lstinline{ =============================}\\
   \lstinline{+}\\
   \lstinline{+My favorite character is Milhouse.}
  \end{framed}
\end{pframe}

\subsection{Creating a merge conflict}
540 541 542 543 544 545 546 547 548 549 550 551
\begin{pframe}
 \vspace{-0.5cm}
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
   \textcolor{argument-color}{\lstinline{hue}}\\
   \lstinline{Auto-merging FACTS.md}\\
   \lstinline{CONFLICT (content): Merge conflict in FACTS.md}\\
   \lstinline{Automatic merge failed; fix conflicts and then}\\
   \lstinline{commit the result.}
  \end{framed}
\end{pframe}

Mihai's avatar
Mihai committed
552 553 554 555 556 557 558 559 560 561
\begin{pframe}
 \vspace{-0.5cm}
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
   \textcolor{argument-color}{\lstinline{hue}}\\
   \lstinline{Auto-merging FACTS.md}\\
   \lstinline{CONFLICT (content): Merge conflict in FACTS.md}\\
   \lstinline{Automatic merge failed; fix conflicts and then}\\
   \lstinline{commit the result.}\\
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
562
   \lstinline{# On branch }\textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
   \lstinline{# Unmerged paths:}\\
   \lstinline{#   (use "git add/rm <file>.." as appropriate)}\\
   \lstinline{#    to mark resolution)}\\
   \lstinline{#              both modified:      FACTS.md}\\
   \lstinline{# no changes added to commit (use "git add" and/or}\\
   \lstinline{# "git commit -a")}
  \end{framed}
\end{pframe}

\subsection{Resolving a merge conflict (1/3)}
\begin{pframe}
 \begin{framed}
  \textcolor{cli-text}{
   \lstinline{$} \textcolor{command-color}{\lstinline{cat}} \textcolor{argument-color}{\lstinline{FACTS.md}}\\
   \lstinline{Facts about television series}\\
   \lstinline{=============================}\\
   \textcolor{white}{\lstinline{S}}\\
   \lstinline{<<<<<<< HEAD}\\
   \lstinline{My favorite character is Eric Cartman.}\\
   \lstinline{=======}\\
   \lstinline{My favorite character is Milhouse.}\\
   \lstinline{>>>>>>> hue}
  }
  \end{framed}

  What we had is under \lstinline{HEAD}, what \lstinline{hue} had is
  above \lstinline{hue}.
\end{pframe}

\subsection{Resolving a merge conflict (2/3)}
\begin{pframe}
  We resolve the conflict by hand.
 \begin{framed}
   \lstinline{$} \textcolor{command-color}{\lstinline{nano}} \textcolor{argument-color}{\lstinline{FACTS.md}} \\
   \lstinline{$} \textcolor{command-color}{\lstinline{cat}} \textcolor{argument-color}{\lstinline{FACTS.md}} \\
   \lstinline{Facts about television series}\\
   \lstinline{=============================}\\
   \textcolor{white}{\lstinline{S}}\\
   \lstinline{My favorite characters are Eric Cartman}\\
   \lstinline{and Milhouse.}
  \end{framed}
\end{pframe}

\subsection{Resolving a merge conflict (3/3)}
\begin{pframe}
  And can now finish the merge commit.
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{add}} \textcolor{argument-color}{\lstinline{FACTS.md}} \\
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{commit}} \\
612
   \lstinline{[}\textcolor{branch}{\lstinline{master}}\lstinline{ }\textcolor{commit-id}{\lstinline{1e496cb}}\lstinline{] Merge branch 'hue'}
Mihai's avatar
Mihai committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
  \end{framed}
\end{pframe}


\subsection{Aborting a merge}
\begin{pframe}
  If you don't feel like resolving the merge conflict, you can go back with
  \lstinline{git merge --abort}.
 \begin{framed}
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}} \textcolor{argument-color}{\lstinline{hue}} \\
   \lstinline{Auto-merging FACTS.md}\\
   \lstinline{CONFLICT (content): Merge conflict in FACTS.md}\\
   \lstinline{Automatic merge failed; fix conflicts and then}\\
   \lstinline{commit the result.}\\
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}} \textcolor{argument-color}{\lstinline{--abort}} \\
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
629
   \lstinline{# On branch }\textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
   \lstinline{# nothing to commit (working directory clean)}
  \end{framed}
\end{pframe}

\subsection{Resolving conflicts with \lstinline{git mergetool}}
\begin{pframe}
  We can also use graphical merge tools such as {\em Meld}.
 \begin{framed}
  \textcolor{cli-text}{
   \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{mergetool}}\\
   \lstinline{merge tool candidates: meld opendiff kdiff3 ...}\\
   \lstinline{Merging:}\\
   \lstinline{FACTS.md}\\
   \textcolor{white}{\lstinline{S}}\\
   \lstinline{Normal merge conflict for 'FACTS.md':}\\
   \textcolor{white}{\lstinline{ss}}\lstinline{local: modified file}\\
   \textcolor{white}{\lstinline{ss}}\lstinline{remote: modified file}\\
   \lstinline{Hit return to start merge resolution tool (meld):}
  }
  \end{framed}
\end{pframe}

\subsection{Meld example}
\begin{pframe}
  \includegraphics[width=11cm]{meld}
  \smallskip

  Tools like Meld provide an editable three-way diff.
\end{pframe}

\makeAcknowledgementsSlide{
  \begin{tabular}{l}
    \acknowledgements
  \end{tabular}
  \bigskip

  \hfill\includegraphics[width=3.5cm]{../shared/git_logo.pdf}

  \begin{tabular}{l}
    \small\url{http://git-scm.com/book}\\
    \small\url{https://www.atlassian.com/git}
  \end{tabular}
}

\end{document}