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

\usepackage{framed}

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

Mihai's avatar
Mihai committed
7
\author{}
Mihai's avatar
Mihai committed
8
\title{\courseTitle}
9
\providecommand{\mySubTitle}{The git commit graph}
Mihai's avatar
Mihai committed
10 11
\providecommand{\myConference}{\courseTitle}
\providecommand{\myGroup}{}
Mihai's avatar
Mihai committed
12 13
\providecommand{\myDepartment}{}
\providecommand{\myCenter}{}
Mihai's avatar
Mihai committed
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


\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}}

46
\section{The git commit graph}
Mihai's avatar
Mihai committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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
\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}}\\
120
    \lstinline{On branch} \textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
121 122 123 124 125 126 127 128 129 130 131 132
    \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}\\
133
    \lstinline{* }\textcolor{branch}{\lstinline{master}}
Mihai's avatar
Mihai committed
134 135 136
  \end{framed}
  \vspace{-0.3cm}

137
  Three branches, current branch is  \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
138 139 140 141 142
  \pause
  \vspace{-0.3cm}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}} \textcolor{argument-color}{\lstinline{-v}}\\
143 144 145
    \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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  \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
178
    \lstinline{|\}\\
Mihai's avatar
Mihai committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    \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}}\\
197
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{interface}}\lstinline{'}
Mihai's avatar
Mihai committed
198 199 200
  \end{framed}
  \vspace{-0.2cm}
  \begin{itemize}
201
   \item Points \textcolor{head}{\lstinline{HEAD}} to the named branch.
Mihai's avatar
Mihai committed
202 203 204 205 206 207
   \item Updates your working directory.
  \end{itemize}
  \pause

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
208
    \lstinline{On branch }\textcolor{branch}{\lstinline{interface}}\\
Mihai's avatar
Mihai committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    \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}}\\
229 230
    \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
231 232 233 234 235 236 237 238
%     \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>}\\ \\
239
    \textcolor{head}{\lstinline{HEAD}}\lstinline{ is now at }\textcolor{commit-id}{\lstinline{4a44c4e}}\lstinline{... Merge Branch 'license'}
Mihai's avatar
Mihai committed
240 241 242 243 244 245
  \end{framed}
\end{pframe}

\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{status}}\\
246
    \textcolor{red}{\lstinline{HEAD detached at}}\lstinline{ }\textcolor{commit-id}{\lstinline{4a44c4e}}\\
Mihai's avatar
Mihai committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    \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}

278
  Creates branch \textcolor{branch}{\lstinline{lib}} at \textcolor{head}{\lstinline{HEAD}}.
Mihai's avatar
Mihai committed
279 280
  \pause
  \medskip
281

282
  How can I see that it worked?
Mihai's avatar
Mihai committed
283 284 285 286 287 288 289 290
  \pause
  \vspace{-0.3cm}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch}}\\
    \lstinline{  interface}\\
    \lstinline{  lib}\\
    \lstinline{  license}\\
291
    \lstinline{* }\textcolor{branch}{\lstinline{master}}
Mihai's avatar
Mihai committed
292 293 294
  \end{framed}
  \vspace{-0.2cm}
  \pause
295

296
  How can I switch to the new \textcolor{branch}{\lstinline{lib}} branch?
Mihai's avatar
Mihai committed
297
\end{pframe}
298

Mihai's avatar
Mihai committed
299 300 301
\begin{pframe}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}} \textcolor{argument-color}{\lstinline{lib}}\\
302
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{lib}}\lstinline{'}
Mihai's avatar
Mihai committed
303 304
  \end{framed}
\end{pframe}
305

Mihai's avatar
Mihai committed
306 307 308 309 310
\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}} \\
311
    \lstinline{Switched to a new branch '}\textcolor{branch}{\lstinline{lib}}\lstinline{'}
Mihai's avatar
Mihai committed
312 313
  \end{framed}

314 315
  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
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 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
\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}
364
  Let's merge our work on \textcolor{branch}{\lstinline{lib}} back into \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
365 366 367
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{checkout}}
    \textcolor{argument-color}{\lstinline{master}} \\
368
    \lstinline{Switched to branch '}\textcolor{branch}{\lstinline{master}}\lstinline{'}\\
Mihai's avatar
Mihai committed
369 370
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
    \textcolor{argument-color}{\lstinline{lib}}\\
371
    \lstinline{Updating }\textcolor{commit-id}{\lstinline{c7f3bd9}}\lstinline{..}\textcolor{commit-id}{\lstinline{251a51b}}\\
Mihai's avatar
Mihai committed
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    \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}
388
  Let's merge our work on \textcolor{branch}{\lstinline{interface}} back into \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
389 390 391 392 393 394 395 396 397 398 399 400
  \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}
401 402 403
    \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
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
    \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}

421 422 423 424
\subsection{Note}
\begin{pframe}
  Make sure that the working directory is clean before merging.
  \medskip
425

426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
  Otherwise:
  \vspace{-0.3cm}
  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{merge}}
    \textcolor{argument-color}{\lstinline{lib}}\\
    \lstinline{error: Your local changes to the following files}\\
    \lstinline{       would be overwritten by merge:}\\
    \lstinline{        testlib.py}\\
    \lstinline{Please, commit your changes or stash them before}\\
    \lstinline{you can merge.}\\
    \lstinline{Aborting}
  \end{framed}

\end{pframe}

Mihai's avatar
Mihai committed
441 442


Mihai's avatar
Mihai committed
443 444 445 446 447 448
\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}}\\
449
    \lstinline{Deleted branch }\textcolor{branch}{\lstinline{interface}}\lstinline{ (was }\textcolor{commit-id}{{8fc25c1}}\lstinline{).}
Mihai's avatar
Mihai committed
450 451 452 453 454
  \end{framed}

  \begin{framed}
    \lstinline{$} \textcolor{git-color}{\lstinline{git}} \textcolor{command-color}{\lstinline{branch -d}}
    \textcolor{argument-color}{\lstinline{lib license}}\\
455 456
    \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
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 491 492 493
  \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}}\\
494 495
   \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
496
   \lstinline{|/}\\
497
   \lstinline{* }\textcolor{commit-id}{\lstinline{1f6d2ab}}\lstinline{ Initial commit}
Mihai's avatar
Mihai committed
498 499
  \end{framed}

500
  We'd like to merge branch \textcolor{branch}{\lstinline{hue}} into \textcolor{branch}{\lstinline{master}}.
Mihai's avatar
Mihai committed
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 540 541 542
\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}
543 544 545 546 547 548 549 550 551 552 553 554
\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
555 556 557 558 559 560 561 562 563 564
\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}}\\
565
   \lstinline{# On branch }\textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
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
   \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}

591 592
  What we had is under \textcolor{head}{\lstinline{HEAD}}, what \textcolor{branch}{\lstinline{hue}} had is
  above \textcolor{branch}{\lstinline{hue}}.
Mihai's avatar
Mihai committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
\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}} \\
615
   \lstinline{[}\textcolor{branch}{\lstinline{master}}\lstinline{ }\textcolor{commit-id}{\lstinline{1e496cb}}\lstinline{] Merge branch 'hue'}
Mihai's avatar
Mihai committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
  \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}}\\
632
   \lstinline{# On branch }\textcolor{branch}{\lstinline{master}}\\
Mihai's avatar
Mihai committed
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 675 676 677
   \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}