branching_handouts.tex 2.32 KB
 Vermaat committed Oct 14, 2013 1 2 \documentclass{article}  Laros committed Apr 24, 2016 3 \providecommand{\handoutsTitle}{Working with branches in Git}  Vermaat committed Oct 14, 2013 4   Laros committed Apr 24, 2016 5 6 \usepackage{handouts} \input{../shared/shared}  Vermaat committed Oct 14, 2013 7   Laros committed Apr 24, 2016 8 9 \begin{document} \makeHeader  Vermaat committed Oct 14, 2013 10   Laros committed Apr 24, 2016 11 \subsubsection*{Inspect the commit graph}  Vermaat committed Oct 14, 2013 12 13 14 We'll work from the repository you created in the previous practical. \begin{itemize}  Vermaat committed Jun 20, 2014 15  \item \emph{Question:} What is your current branch and what is the hash of  Vermaat committed Oct 14, 2013 16 17  the commit it points to? \item \emph{Question:} What does the commit graph of you repository look  Vermaat committed Jun 20, 2014 18  like? Can you draw it on paper?  Vermaat committed Oct 14, 2013 19 \end{itemize}  Laros committed Apr 24, 2016 20 \emph{Hint:} Use \lstinline{git log} with the appropriate arguments.  Vermaat committed Oct 14, 2013 21 22 \bigskip  Laros committed Apr 24, 2016 23 24 As an alternative to \lstinline{git log}, you can also try a graphical viewer such as \lstinline{gitg} (installed on the course laptops) or \lstinline{gitk}.  Vermaat committed Jun 20, 2014 25 26 \bigskip  Laros committed Apr 24, 2016 27 \subsubsection*{Implement a feature in a new branch}  Vermaat committed Oct 14, 2013 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 Let's do some real work (e.g., add some documentation to the project). \bigskip Start by creating a branch for your work (give it a descriptive name) and switch to it. \begin{itemize} \item \emph{Question:} What branches are there now and what are the commits they point to? \end{itemize} \bigskip Implement your feature (e.g. write documentation) and commit your changes. \begin{itemize} \item \emph{Question:} What does the commit graph of you repository look like now? \end{itemize} \bigskip  Laros committed Apr 24, 2016 48 49 \subsubsection*{Merge your feature} Of course we want this nice feature in our \lstinline{master} branch.  Vermaat committed Oct 14, 2013 50 51 52 \bigskip \begin{itemize}  Laros committed Apr 24, 2016 53 54  \item \emph{Question:} If you want to merge branch \lstinline{B} into branch \lstinline{A}, what should be your current branch?  Vermaat committed Oct 14, 2013 55 56 57 \end{itemize} \bigskip  Laros committed Apr 24, 2016 58 Merge your feature branch into \lstinline{master}.  Vermaat committed Oct 14, 2013 59 60 61 62 63 64 65 66  \begin{itemize} \item \emph{Question:} What does the commit graph of you repository look like now? \end{itemize} \bigskip Since you merged it, you can now delete the feature branch.  Vermaat committed Jun 20, 2014 67 68 \bigskip  Laros committed Apr 24, 2016 69 \subsubsection*{A three-way merge}  Vermaat committed Jun 20, 2014 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 Unless you were extremely zealous, the last section produced a fast-forward merge. \bigskip \begin{itemize} \item \emph{Question:} Can you think of a way to get a three-way merge? \end{itemize} \bigskip Manipulate your repository in such a way that the commit graph contains a merge commit (created by a three-way merge). \begin{itemize} \item \emph{Question:} What does the commit graph of you repository look like now? \end{itemize}  Vermaat committed Oct 14, 2013 87 \end{document}