Commit 9392ae2f authored by Vermaat's avatar Vermaat
Browse files

Finish merging lecture

parent fb3a9271
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -168,167 +168,89 @@ $ git log --oneline --decorate --graph --all ...@@ -168,167 +168,89 @@ $ git log --oneline --decorate --graph --all
\begin{frame} \begin{frame}
\frametitle{Remote branches} \frametitle{Remote branches}
In this course, we don't really use branches, except: In this course, we don't really discuss branches, except:
\begin{itemize} \begin{itemize}
\item Commits from a remote show up as a remote branch. \item Commits from a remote show up as a remote branch.
\item Even with only a \bt{master} branch, remotes might still diverge. \item Even with only a \bt{master} branch, remotes might still diverge.
\item Merging remote branches is just like merging local branches. \item Merging remote branches is just like merging local branches.
\end{itemize} \end{itemize}
\bigskip \bigskip
\includegraphics[width=10cm]{images/example-hue-ahead} \includegraphics[width=10cm]{images/example-hue}
\end{frame} \end{frame}
\section{Manipulating the commit graph} \section{Merging from remotes}
\begin{frame} \begin{frame}
\frametitle{An example repository} \frametitle{An example repository}
\includegraphics[width=8cm]{images/example} \includegraphics[width=10cm]{images/example-hue}\\
\bigskip
Branch \bt{master} on \bt{hue} is one commit ahead of our \bt{master} and we
have already seen how to merge \bt{hue/master} into \bt{master}:
\begin{itemize} \begin{itemize}
\item Branches \bt{license} and \bt{interface} diverged from \bt{master}. \item \bt{git merge hue/master}
\item Only \bt{license} has been merged back into \bt{master}. \item This was easy: Git just moves \bt{master} (and \bt{HEAD}) to point
\item Current branch is \bt{master}. to \bt{hue/master}.
\item It is called a {\em fast forward merge}.
\end{itemize} \end{itemize}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Creating a new branch: \bt{git branch}} \frametitle{Fast forward merging: \bt{git merge}}
\begin{lstlisting} If a remote branch is ahead of us, it can be merged easily:
$ git branch lib
\end{lstlisting}
\bigskip
Creates branch \bt{lib} at \bt{HEAD}.
\pause
\bigskip
\begin{lstlisting}
$ git checkout lib
Switched to branch 'lib'
\end{lstlisting}
\pause
\bigskip
Or, for Git pro's, in one command:
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git checkout -b lib $ git merge hue/master
Switched to a new branch 'lib' Updating c7f3bd9..251a51b
Fast-forward
testlib.py | 2 +
1 file changed, 2 insertions(+)
\end{lstlisting} \end{lstlisting}
\bigskip \bigskip
At this point, \bt{lib} is just a label to the same commit as \bt{master}. \includegraphics[width=10cm]{images/example-hue-merged}
\end{frame} \end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-branched}\\
\vspace{0.5cm}
Created branch \bt{lib} from \bt{master}.
\end{frame}
\begin{frame}[fragile]
\frametitle{Working on a branch: \bt{git commit}}
We can extend the \bt{lib} branch by adding commits.
\bigskip
\begin{lstlisting}
$ echo 'VERSION=1' > testlib.py
$ git add testlib.py
$ git commit -m 'Add empty testlib'
\end{lstlisting}
\pause
\bigskip
\begin{lstlisting}
$ git log --oneline --decorate --graph --all
* 251a51b (HEAD, lib) Add empty testlib
* c7f3bd9 (master) Add .gitignore file
| * 8fc25c1 (interface) Trivial Python interface
|/
* 4a44c4e Merge branch 'license'
|\
| * 0fbe3e3 (license) Add MIT license
...
\end{lstlisting}
\end{frame}
\begin{frame} \begin{frame}
\frametitle{Our example repository} \frametitle{An example repository}
\includegraphics[width=8cm]{images/example-committed}\\ \includegraphics[width=8cm]{images/example-hue-diverged}\\
\vspace{0.5cm}
Extended branch \bt{lib}.
\end{frame}
\begin{frame}[fragile]
\frametitle{Fast forward merging: \bt{git merge}}
Let's merge our work on \bt{lib} back into \bt{master}.
\bigskip
\begin{lstlisting}
$ git checkout master
Switched to branch 'master'
$ git merge lib
Updating c7f3bd9..251a51b
Fast-forward
testlib.py | 1 +
1 file changed, 1 insertion(+)
create mode 100644 testlib.py
\end{lstlisting}
\bigskip \bigskip
This merge was easy: Branch \bt{master} on \bt{hue} and our \bt{master} have diverged and merging
now seems less straightforward.
\begin{itemize} \begin{itemize}
\item \bt{lib} was directly upstream of \bt{master}. \item \bt{git merge hue/master}
\item Git just moves \bt{HEAD} and \bt{master} to point to \bt{lib}. \item Git will create a new commit in which it combines both changes.
\item This is called a {\em fast forward merge}. \item It is called a {\em three-way merge}.
\item The {\em merge commit} has two parents.
\end{itemize} \end{itemize}
\end{frame} \end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-merged-ff}\\
\vspace{0.5cm}
Merged branch \bt{lib} into \bt{master} (fast forward).
\end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Three-way merging: \bt{git merge}} \frametitle{Three-way merging: \bt{git merge}}
Let's merge our work on \bt{interface} back into \bt{master}. Let's merge the remote work on \bt{master} back into our local \bt{master}:
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git merge interface $ git merge hue/master
Merge made by the 'recursive' strategy. Merge made by the 'recursive' strategy.
interface.py | 3 +++ FACTS.md | 2 +-
1 file changed, 3 insertions(+) 1 file changed, 1 insertion(+), 1 deletion(-)
create mode 100755 interface.py
\end{lstlisting} \end{lstlisting}
\bigskip \bigskip
This merge was harder: \includegraphics[width=9cm]{images/example-hue-merged2}
\begin{itemize}
\item \bt{interface} and \bt{master} had diverged.
\item Git determines changes in \bt{interface} and \bt{master} since their
most recent common ancestor and creates a new commit from that.
\item This is called a {\em recursive three-way merge} and the resulting
merge a {\em merge commit}.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-merged}\\
\vspace{0.5cm}
Merged branch \bt{interface} into \bt{master}.
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Deleting branches: \bt{git branch}} \frametitle{The other way around}
Old branches that have been merged can be deleted. \bt{git push} also does an implicit \bt{git merge} on the remote.
\bigskip \begin{itemize}
\begin{lstlisting} \item We send our local commits to the remote.
$ git branch -d interface \item They are merged into the remote branch.
Deleted branch interface (was 8fc25c1). \item But only if this is a fast-forward merge.
\end{lstlisting} \item Diverging commits {\em cannot be pushed directly}.
\end{itemize}
\bigskip \bigskip
\begin{lstlisting}
$ git branch -d lib license
Deleted branch lib (was 251a51b).
Deleted branch license (was 0fbe3e3).
\end{lstlisting}
\bigskip \bigskip
No history is lost, just labels removed. \includegraphics[width=10cm]{images/example-hue-pushed}
\end{frame} \end{frame}
...@@ -355,14 +277,13 @@ Deleted branch license (was 0fbe3e3). ...@@ -355,14 +277,13 @@ Deleted branch license (was 0fbe3e3).
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Setting the stage (1/3)} \frametitle{Setting the stage (1/3)}
\begin{lstlisting} \begin{lstlisting}
$ git log --oneline --decorate --graph --all * 5edaf08 (hue/master, hue/HEAD) State character preference
* 9d2ad27 (HEAD, master) State character preference | * f1ef19c (HEAD, master) State character preference
| * 374ab60 (simpsons) State character preference
|/ |/
* 4012f4f Initial commit * 1f6d2ab Initial commit
\end{lstlisting} \end{lstlisting}
\bigskip \bigskip
We'd like to merge branch \bt{simpsons} into \bt{master}. We'd like to merge branch \bt{hue/master} into \bt{master}.
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
...@@ -370,15 +291,14 @@ $ git log --oneline --decorate --graph --all ...@@ -370,15 +291,14 @@ $ git log --oneline --decorate --graph --all
The last commit on \bt{master}: The last commit on \bt{master}:
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git show --oneline f1ef19c State character preference
9d2ad27 State character preference diff --git a/FACTS.md b/FACTS.md
diff --git a/README b/README
index de15194..ef40359 100644 index de15194..ef40359 100644
--- a/README --- a/FACTS.md
+++ b/README +++ b/FACTS.md
@@ -1,2 +1,4 @@ @@ -1,2 +1,4 @@
Facts about television series Facts about television series
============================= =============================
+ +
+My favorite character is Eric Cartman. +My favorite character is Eric Cartman.
\end{lstlisting} \end{lstlisting}
...@@ -386,29 +306,29 @@ index de15194..ef40359 100644 ...@@ -386,29 +306,29 @@ index de15194..ef40359 100644
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Setting the stage (3/3)} \frametitle{Setting the stage (3/3)}
The last commit on \bt{simpsons}: The last commit on \bt{hue/master}:
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git show --oneline simpsons $ git show --oneline hue/master
374ab60 State character preference 5edaf08 State character preference
diff --git a/README b/README diff --git a/FACTS.md b/FACTS.md
index de15194..9dd729b 100644 index de15194..5e69508 100644
--- a/README --- a/FACTS.md
+++ b/README +++ b/FACTS.md
@@ -1,2 +1,4 @@ @@ -1,2 +1,4 @@
Facts about television series Facts about television series
============================= =============================
+ +
+My favorite character is Homer Simpson. +My favorite character is Milhouse.
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Creating a merge conflict} \frametitle{Creating a merge conflict}
\begin{lstlisting} \begin{lstlisting}
$ git merge simpsons $ git merge hue/master
Auto-merging README Auto-merging FACTS.md
CONFLICT (content): Merge conflict in README CONFLICT (content): Merge conflict in FACTS.md
Automatic merge failed; fix conflicts and then Automatic merge failed; fix conflicts and then
commit the result. commit the result.
\end{lstlisting} \end{lstlisting}
...@@ -420,7 +340,7 @@ $ git status ...@@ -420,7 +340,7 @@ $ git status
# (use "git add/rm <file>.." as appropriate to # (use "git add/rm <file>.." as appropriate to
# mark resolution) # mark resolution)
# #
# both modified: README # both modified: FACTS.md
# #
no changes added to commit (use "git add" and/or no changes added to commit (use "git add" and/or
"git commit -a") "git commit -a")
...@@ -430,23 +350,23 @@ no changes added to commit (use "git add" and/or ...@@ -430,23 +350,23 @@ no changes added to commit (use "git add" and/or
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Resolving a merge conflict (1/2)} \frametitle{Resolving a merge conflict (1/2)}
\begin{lstlisting} \begin{lstlisting}
$ cat README $ cat FACTS.md
Facts about television series Facts about television series
============================= =============================
<<<<<<< HEAD <<<<<<< HEAD
My favorite character is Eric Cartman. My favorite character is Eric Cartman.
======= =======
My favorite character is Homer Simpson. My favorite character is Milhouse.
>>>>>>> simpsons >>>>>>> hue/master
\end{lstlisting} \end{lstlisting}
\bigskip \bigskip
What we had is under \bt{HEAD}, what \bt{simpsons} had is above What we had is under \bt{HEAD}, what \bt{hue/master} had is above
\bt{simpsons}. \bt{hue/maser}.
\pause \pause
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ emacs README $ nano FACTS.md
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
...@@ -455,21 +375,21 @@ $ emacs README ...@@ -455,21 +375,21 @@ $ emacs README
We resolve the conflict by hand. We resolve the conflict by hand.
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ cat README $ cat FACTS.md
Facts about television series Facts about television series
============================= =============================
My favorite characters are Eric Cartman My favorite characters are Eric Cartman
and Homer Simpson. and Milhouse.
\end{lstlisting} \end{lstlisting}
\pause \pause
\bigskip \bigskip
And can now finish the merge commit. And can now finish the merge commit.
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git add README $ git add FACTS.md
$ git commit $ git commit
[master 1e496cb] Merge branch 'simpsons' [master 1e496cb] Merge remote-tracking branch 'hue/master'
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
...@@ -479,9 +399,9 @@ $ git commit ...@@ -479,9 +399,9 @@ $ git commit
\bt{git merge --abort}. \bt{git merge --abort}.
\bigskip \bigskip
\begin{lstlisting} \begin{lstlisting}
$ git merge simpsons $ git merge hue/master
Auto-merging README Auto-merging FACTS.md
CONFLICT (content): Merge conflict in README CONFLICT (content): Merge conflict in FACTS.md
Automatic merge failed; fix conflicts and then Automatic merge failed; fix conflicts and then
commit the result. commit the result.
\end{lstlisting} \end{lstlisting}
...@@ -505,9 +425,9 @@ nothing to commit (working directory clean) ...@@ -505,9 +425,9 @@ nothing to commit (working directory clean)
$ git mergetool $ git mergetool
merge tool candidates: meld opendiff kdiff3 ... merge tool candidates: meld opendiff kdiff3 ...
Merging: Merging:
README FACTS.md
Normal merge conflict for 'README': Normal merge conflict for 'FACTS.md':
{local}: modified file {local}: modified file
{remote}: modified file {remote}: modified file
Hit return to start merge resolution tool (meld): Hit return to start merge resolution tool (meld):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment