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

Finish merging lecture

parent fb3a9271
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -168,167 +168,89 @@ $ git log --oneline --decorate --graph --all
\begin{frame}
\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}
\item Commits from a remote show up as a remote branch.
\item Even with only a \bt{master} branch, remotes might still diverge.
\item Merging remote branches is just like merging local branches.
\end{itemize}
\bigskip
\includegraphics[width=10cm]{images/example-hue-ahead}
\includegraphics[width=10cm]{images/example-hue}
\end{frame}
\section{Manipulating the commit graph}
\section{Merging from remotes}
\begin{frame}
\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}
\item Branches \bt{license} and \bt{interface} diverged from \bt{master}.
\item Only \bt{license} has been merged back into \bt{master}.
\item Current branch is \bt{master}.
\item \bt{git merge hue/master}
\item This was easy: Git just moves \bt{master} (and \bt{HEAD}) to point
to \bt{hue/master}.
\item It is called a {\em fast forward merge}.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Creating a new branch: \bt{git branch}}
\begin{lstlisting}
$ 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:
\frametitle{Fast forward merging: \bt{git merge}}
If a remote branch is ahead of us, it can be merged easily:
\bigskip
\begin{lstlisting}
$ git checkout -b lib
Switched to a new branch 'lib'
$ git merge hue/master
Updating c7f3bd9..251a51b
Fast-forward
testlib.py | 2 +
1 file changed, 2 insertions(+)
\end{lstlisting}
\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}
\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}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-committed}\\
\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}
\frametitle{An example repository}
\includegraphics[width=8cm]{images/example-hue-diverged}\\
\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}
\item \bt{lib} was directly upstream of \bt{master}.
\item Git just moves \bt{HEAD} and \bt{master} to point to \bt{lib}.
\item This is called a {\em fast forward merge}.
\item \bt{git merge hue/master}
\item Git will create a new commit in which it combines both changes.
\item It is called a {\em three-way merge}.
\item The {\em merge commit} has two parents.
\end{itemize}
\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]
\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
\begin{lstlisting}
$ git merge interface
$ git merge hue/master
Merge made by the 'recursive' strategy.
interface.py | 3 +++
1 file changed, 3 insertions(+)
create mode 100755 interface.py
FACTS.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
\end{lstlisting}
\bigskip
This merge was harder:
\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}.
\includegraphics[width=9cm]{images/example-hue-merged2}
\end{frame}
\begin{frame}[fragile]
\frametitle{Deleting branches: \bt{git branch}}
Old branches that have been merged can be deleted.
\bigskip
\begin{lstlisting}
$ git branch -d interface
Deleted branch interface (was 8fc25c1).
\end{lstlisting}
\frametitle{The other way around}
\bt{git push} also does an implicit \bt{git merge} on the remote.
\begin{itemize}
\item We send our local commits to the remote.
\item They are merged into the remote branch.
\item But only if this is a fast-forward merge.
\item Diverging commits {\em cannot be pushed directly}.
\end{itemize}
\bigskip
\begin{lstlisting}
$ git branch -d lib license
Deleted branch lib (was 251a51b).
Deleted branch license (was 0fbe3e3).
\end{lstlisting}
\bigskip
No history is lost, just labels removed.
\includegraphics[width=10cm]{images/example-hue-pushed}
\end{frame}
......@@ -355,14 +277,13 @@ Deleted branch license (was 0fbe3e3).
\begin{frame}[fragile]
\frametitle{Setting the stage (1/3)}
\begin{lstlisting}
$ git log --oneline --decorate --graph --all
* 9d2ad27 (HEAD, master) State character preference
| * 374ab60 (simpsons) State character preference
* 5edaf08 (hue/master, hue/HEAD) State character preference
| * f1ef19c (HEAD, master) State character preference
|/
* 4012f4f Initial commit
* 1f6d2ab Initial commit
\end{lstlisting}
\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}
\begin{frame}[fragile]
......@@ -370,15 +291,14 @@ $ git log --oneline --decorate --graph --all
The last commit on \bt{master}:
\bigskip
\begin{lstlisting}
$ git show --oneline
9d2ad27 State character preference
diff --git a/README b/README
f1ef19c State character preference
diff --git a/FACTS.md b/FACTS.md
index de15194..ef40359 100644
--- a/README
+++ b/README
--- a/FACTS.md
+++ b/FACTS.md
@@ -1,2 +1,4 @@
Facts about television series
=============================
Facts about television series
=============================
+
+My favorite character is Eric Cartman.
\end{lstlisting}
......@@ -386,29 +306,29 @@ index de15194..ef40359 100644
\begin{frame}[fragile]
\frametitle{Setting the stage (3/3)}
The last commit on \bt{simpsons}:
The last commit on \bt{hue/master}:
\bigskip
\begin{lstlisting}
$ git show --oneline simpsons
374ab60 State character preference
diff --git a/README b/README
index de15194..9dd729b 100644
--- a/README
+++ b/README
$ git show --oneline hue/master
5edaf08 State character preference
diff --git a/FACTS.md b/FACTS.md
index de15194..5e69508 100644
--- a/FACTS.md
+++ b/FACTS.md
@@ -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{frame}
\begin{frame}[fragile]
\frametitle{Creating a merge conflict}
\begin{lstlisting}
$ git merge simpsons
Auto-merging README
CONFLICT (content): Merge conflict in README
$ git merge hue/master
Auto-merging FACTS.md
CONFLICT (content): Merge conflict in FACTS.md
Automatic merge failed; fix conflicts and then
commit the result.
\end{lstlisting}
......@@ -420,7 +340,7 @@ $ git status
# (use "git add/rm <file>.." as appropriate to
# mark resolution)
#
# both modified: README
# both modified: FACTS.md
#
no changes added to commit (use "git add" and/or
"git commit -a")
......@@ -430,23 +350,23 @@ no changes added to commit (use "git add" and/or
\begin{frame}[fragile]
\frametitle{Resolving a merge conflict (1/2)}
\begin{lstlisting}
$ cat README
$ cat FACTS.md
Facts about television series
=============================
<<<<<<< HEAD
My favorite character is Eric Cartman.
=======
My favorite character is Homer Simpson.
>>>>>>> simpsons
My favorite character is Milhouse.
>>>>>>> hue/master
\end{lstlisting}
\bigskip
What we had is under \bt{HEAD}, what \bt{simpsons} had is above
\bt{simpsons}.
What we had is under \bt{HEAD}, what \bt{hue/master} had is above
\bt{hue/maser}.
\pause
\bigskip
\begin{lstlisting}
$ emacs README
$ nano FACTS.md
\end{lstlisting}
\end{frame}
......@@ -455,21 +375,21 @@ $ emacs README
We resolve the conflict by hand.
\bigskip
\begin{lstlisting}
$ cat README
$ cat FACTS.md
Facts about television series
=============================
My favorite characters are Eric Cartman
and Homer Simpson.
and Milhouse.
\end{lstlisting}
\pause
\bigskip
And can now finish the merge commit.
\bigskip
\begin{lstlisting}
$ git add README
$ git add FACTS.md
$ git commit
[master 1e496cb] Merge branch 'simpsons'
[master 1e496cb] Merge remote-tracking branch 'hue/master'
\end{lstlisting}
\end{frame}
......@@ -479,9 +399,9 @@ $ git commit
\bt{git merge --abort}.
\bigskip
\begin{lstlisting}
$ git merge simpsons
Auto-merging README
CONFLICT (content): Merge conflict in README
$ git merge hue/master
Auto-merging FACTS.md
CONFLICT (content): Merge conflict in FACTS.md
Automatic merge failed; fix conflicts and then
commit the result.
\end{lstlisting}
......@@ -505,9 +425,9 @@ nothing to commit (working directory clean)
$ git mergetool
merge tool candidates: meld opendiff kdiff3 ...
Merging:
README
FACTS.md
Normal merge conflict for 'README':
Normal merge conflict for 'FACTS.md':
{local}: modified file
{remote}: modified file
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