commit_graph_handouts.tex 8.67 KB
Newer Older
Mihai's avatar
Mihai committed
1 2
\documentclass{article}

Mihai's avatar
Mihai committed
3
\providecommand{\handoutsTitle}{\vspace{0.5cm}The git commit graph}
Mihai's avatar
Mihai committed
4 5 6

\usepackage{handouts}

Mihai's avatar
Mihai committed
7 8 9 10 11
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{graphicx}

12 13
\input{../shared/shared}

Mihai's avatar
Mihai committed
14 15 16
\begin{document}
\makeHeader

Mihai's avatar
Mihai committed
17 18
\section{General questions}
\begin{enumerate}
Mihai's avatar
Mihai committed
19
  \item A \gitcmd\ branch is:
Mihai's avatar
Mihai committed
20 21 22 23 24
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
    \item a file
    \item always a problem
Mihai's avatar
Mihai committed
25 26 27
    \item a pointer to a commit
    \item a merge conflict
    \item where leaves could grow
Mihai's avatar
Mihai committed
28 29 30 31 32
    \item none of the above
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

33 34 35 36 37 38 39 40 41 42 43 44 45 46
  \item How can you see the commit history in a tree alike manner?
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
    \item git state
    \item git repository
    \item git commit
    \item git status --tree
    \item git show tree
    \item git log --graph
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

Mihai's avatar
Mihai committed
47
  \item What command could be used in joining two or more development histories (branches) together?
Mihai's avatar
Mihai committed
48 49 50
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
Mihai's avatar
Mihai committed
51 52 53 54 55 56
    \item git join
    \item git combine
    \item git merge
    \item git pull
    \item git fork
    \item git intersect
Mihai's avatar
Mihai committed
57 58 59 60
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

Mihai's avatar
Mihai committed
61
  \item Which of the following commands displays the branches list?
Mihai's avatar
Mihai committed
62 63 64
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
Mihai's avatar
Mihai committed
65 66 67 68 69 70
    \item git show-branch
    \item git merge
    \item git display
    \item git branch
    \item git list
    \item git clone
Mihai's avatar
Mihai committed
71 72 73
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}
74

Mihai's avatar
Mihai committed
75 76 77 78 79 80 81 82 83 84 85 86 87
  \item Which of the following creates a new branch called \colorbox{gray!20}{brand\_new} and also checks it out?
  \vspace{-0.2cm}
  \begin{multicols}{3}
  \begin{enumerate}[label=(\alph*)]
    \item git branch -c branch\_new
    \item git new branch branch\_new
    \item git status brand\_new
    \item git checkout -b brand\_new
    \item git commit brand\_mew
    \item none of the above
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}
88

89
  \item In order to merge a branch do we have to add and commit, or discard any changes first?
Mihai's avatar
Mihai committed
90 91 92
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
Mihai's avatar
Mihai committed
93 94
    \item yes
    \item no
Mihai's avatar
Mihai committed
95 96 97
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}
98

Mihai's avatar
Mihai committed
99 100 101 102 103 104 105 106 107 108 109
  \item If we want to merge \colorbox{gray!20}{brand\_new} into \colorbox{gray!20}{master}, which branch should be checked out when we run the command \colorbox{gray!20}{git merge brand\_new}?
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item brand\_new
    \item any branch
    \item master
    \item none of the above
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}
110

Mihai's avatar
Mihai committed
111
  \item Which of the following commands will delete the branch \colorbox{gray!20}{brand\_new}?
Mihai's avatar
Mihai committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item it is impossible to delete a branch
    \item git delete branch brand\_new
    \item git head -d brand\_new
    \item git branch -d brand\_new
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}

  \item You are in a detached head state when:
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item there is no head
    \item the head points to the master branch
    \item the head points to a commit
    \item the head points to a different branch then the master branch
  \end{enumerate}
  \end{multicols}
  \vspace{-0.3cm}
134

Mihai's avatar
Mihai committed
135 136 137 138
\end{enumerate}

\section{Inspecting the commit graph}

Mihai's avatar
Mihai committed
139
In the following you will work with the repository present in \colorbox{gray!20}{$\sim$/commit-graph-practical}.
Mihai's avatar
Mihai committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153
Please navigate to that directory and try to use the commands presented during the lecture (with their options accordingly) to perform the following tasks and answer the corresponding questions.

\begin{enumerate}
  \item How many branches are there?
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item none
    \item only the master branch
    \item 4
    \item 3
  \end{enumerate}
  \end{multicols}

Mihai's avatar
Mihai committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  \item Are you in a detached head state?
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item yes
    \item no
  \end{enumerate}
  \end{multicols}

  \item What branch is active (checked out)?
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item data
    \item data-europe
    \item documentation
    \item master
  \end{enumerate}
  \end{multicols}
173

Mihai's avatar
Mihai committed
174 175 176 177 178 179
  \item The commit graph looks like:
  \vspace{-0.2cm}
  \begin{center}
    \includegraphics[width=\textwidth]{images/initial_practical_graph.pdf}
  \end{center}

Mihai's avatar
Mihai committed
180
  \item What merge type is performed if branch \colorbox{gray!20}{documentation} is merged into \colorbox{gray!20}{master}?
Mihai's avatar
Mihai committed
181 182 183 184 185 186 187 188 189
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item fast-forward
    \item try-and-leave
    \item three-way
    \item advanced
  \end{enumerate}
  \end{multicols}
190

Mihai's avatar
Mihai committed
191
  \item Merge branch \colorbox{gray!20}{documentation} into \colorbox{gray!20}{master}.
Mihai's avatar
Mihai committed
192

193
  \item What merge type is performed if branch \colorbox{gray!20}{data} is merged into \colorbox{gray!20}{master}?
Mihai's avatar
Mihai committed
194 195 196 197 198 199 200 201 202
  \vspace{-0.2cm}
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item fast-forward
    \item three-way
    \item try-and-leave
    \item advanced
  \end{enumerate}
  \end{multicols}
Mihai's avatar
Mihai committed
203

204
  \item Merge branch \colorbox{gray!20}{data} into \colorbox{gray!20}{master}.
205

Mihai's avatar
Mihai committed
206 207 208 209 210 211 212 213 214 215
\end{enumerate}


\section{More commit graph manipulation}

You have already performed some merging in the previous section, but the repository state was beforehand prepared for you.
Next, you will make some file changes and manipulate the commit graph even further.

\subsection{Fast-forward merging}

Mihai's avatar
Mihai committed
216 217
\begin{enumerate}
  \item Checkout branch \colorbox{gray!20}{data} and create a new branch called \colorbox{gray!20}{data-europe}.
218
  \vspace{-0.2cm}
219

220 221 222 223 224
  \item Checkout branch \colorbox{gray!20}{data-europe}.
  \vspace{-0.1cm}

  \item Edit the \colorbox{gray!20}{data/capitals.txt} file by adding at the end of it Rome as Italy's capital (``Italy:Rome'').
  Do not remove or make any changes to the information already present there.
Mihai's avatar
Mihai committed
225
  \vspace{-0.1cm}
226

Mihai's avatar
Mihai committed
227 228
  \item Stage and commit the changes.
  \vspace{-0.1cm}
229

Mihai's avatar
Mihai committed
230
  \item Checkout branch \colorbox{gray!20}{data} and merge the \colorbox{gray!20}{data-europe} branch into it.
231
  \vspace{-0.1cm}
232

Mihai's avatar
Mihai committed
233
  \item Why was the previous merge a fast-forward one?
234
  \vspace{-0.3cm}
Mihai's avatar
Mihai committed
235 236 237 238 239 240 241 242
  \begin{multicols}{2}
  \begin{enumerate}[label=(\alph*)]
    \item it was not
    \item the branches did not diverge yet
    \item different commits
    \item none of the above
  \end{enumerate}
  \end{multicols}
243

Mihai's avatar
Mihai committed
244
\end{enumerate}
Mihai's avatar
Mihai committed
245

Mihai's avatar
Mihai committed
246
\subsection{Three-way merging without conflicts}
Mihai's avatar
Mihai committed
247

Mihai's avatar
Mihai committed
248 249
\begin{enumerate}
  \item Make sure branch \colorbox{gray!20}{data} is active (checkedout).
250
  \vspace{-0.2cm}
251

Mihai's avatar
Mihai committed
252 253
  \item Correct the USA capital to Washington D.C. in the \colorbox{gray!20}{data/capitals.txt} file.
  \vspace{-0.1cm}
254

Mihai's avatar
Mihai committed
255 256
  \item Stage and commit the changes.
  \vspace{-0.1cm}
257

Mihai's avatar
Mihai committed
258
  \item Checkout branch \colorbox{gray!20}{data-europe}.
259
  \vspace{-0.2cm}
260

Mihai's avatar
Mihai committed
261
  \item Add Paris as capital of France at the end of the \colorbox{gray!20}{data/capitals.txt} file.
262
  \vspace{-0.2cm}
263

Mihai's avatar
Mihai committed
264 265
  \item Stage and commit the changes.
  \vspace{-0.1cm}
266

Mihai's avatar
Mihai committed
267
  \item Checkout branch \colorbox{gray!20}{data} and merge into it the \colorbox{gray!20}{data-europe} branch.
268

Mihai's avatar
Mihai committed
269
\end{enumerate}
Mihai's avatar
Mihai committed
270 271 272

\subsection{Resolving a merge conflict}

Mihai's avatar
Mihai committed
273 274 275
\begin{enumerate}
 \item Make sure branch \colorbox{gray!20}{data} is active (checkedout).
  \vspace{-0.1cm}
276

Mihai's avatar
Mihai committed
277
 \item Add Moscow as capital of Russia at the end of the \colorbox{gray!20}{data/capitals.txt} file.
278
  \vspace{-0.2cm}
279

Mihai's avatar
Mihai committed
280 281
 \item Stage and commit the changes.
  \vspace{-0.1cm}
282

Mihai's avatar
Mihai committed
283
 \item Checkout branch \colorbox{gray!20}{data-europe}.
284
  \vspace{-0.2cm}
285

Mihai's avatar
Mihai committed
286
 \item Add Madrid as Spain's capital at the of the \colorbox{gray!20}{data/capitals.txt} file.
287
  \vspace{-0.2cm}
288

Mihai's avatar
Mihai committed
289 290
 \item Stage and commit the changes.
  \vspace{-0.1cm}
291

Mihai's avatar
Mihai committed
292 293
 \item Checkout branch \colorbox{gray!20}{data} and merge into it the \colorbox{gray!20}{data-europe} branch.
  \vspace{-0.1cm}
294

Mihai's avatar
Mihai committed
295
 \item Solve the merge conflict that was created during the previous step.
296

Mihai's avatar
Mihai committed
297
\end{enumerate}
Mihai's avatar
Mihai committed
298 299


Mihai's avatar
Mihai committed
300
\subsection{Branch deletion}
Mihai's avatar
Mihai committed
301

Mihai's avatar
Mihai committed
302 303 304
\begin{enumerate}
  \item Delete the \colorbox{gray!20}{data-europe} branch.
\end{enumerate}
Mihai's avatar
Mihai committed
305

Mihai's avatar
Mihai committed
306
\vspace{1.5cm}
Mihai's avatar
Mihai committed
307

Mihai's avatar
Mihai committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
% \section{Solutions}
%   \vspace{-0.1cm}
%
%  \begin{multicols}{6}
%   \begin{itemize}
%     \item 1.1 - c
%     \item 1.2 - f
%     \item 1.3 - c
%     \item 1.4 - d
%     \item 1.5 - d
%     \item 1.6 - a
%     \item 1.7 - c
%     \item 1.8 - d
%     \item 1.9 - c
%     \item 2.1 - d
%     \item 2.2 - b
%     \item 2.3 - d
%     \item 2.4 - c
%     \item 2.5 - a
%     \item 2.7 - b
%     \item 3.1.5 - b
%   \end{itemize}
%  \end{multicols}
Mihai's avatar
Mihai committed
331 332 333


\end{document}