Commit da3a5bc3 authored by Grégory Mounié's avatar Grégory Mounié
Browse files

Merge branch 'master' of gricad-gitlab.univ-grenoble-alpes.fr:mounieg/formation-git into master

parents 96b131bf df7670aa
......@@ -7,6 +7,7 @@ TEXANIMS=${patsubst %.script,%.tex,$(ANIMS)}
LATEX=advanced1h30
SLIDES=$(LATEX:%=%-slides)
HANDOUTS=$(LATEX:%=%-handout)
FILE=$(SLIDES:%=%.pdf) $(HANDOUTS:%=%.pdf)
%.tex: %.script %.fig
bin/simple-anim $<
......@@ -29,6 +30,12 @@ all: slides handouts
printf '%s\n\n%s\n' '\documentclass{beamer}' \
'\input{$*}' > $@
upload-gitlab: $(FILES)
ls /tmp/www-git || ( cd /tmp/ && git clone git@gitlab.ensimag.fr:systemes/www-git.git )
cd /tmp/www-git && git pull
cp -a $(FILES) /tmp/www-git/public/
@printf "Documents copié dans /tmp/www-git\n Penser à y faire git commit et git push pour les pousser vers gitlab"
# lualatex necessary because one developper of git has a vietnamese name
PDFLATEX=lualatex
PDFLATEX_OPTIONS=-file-line-error -shell-escape
......
......@@ -20,7 +20,7 @@
\author{Sylvain Bouveret, Grégory Mounié, Matthieu Moy}
\institute[first.last@imag.fr]{[first].[last]@imag.fr\\
\url{http://ensiwiki.ensimag.fr}}
\url{http://systemes.pages.ensimag.fr/www-git/}}
\date{2019}
......@@ -35,7 +35,7 @@
\begin{frame}
\frametitle{Goals of the presentation}
Assumptions: basic Git (add,commit,push,pull) (one slide recall)
Assumptions: basic Git (add,commit,push,pull) (one slide recall).
\begin{itemize}
\item Few historical facts
......@@ -58,7 +58,7 @@
\end{center}
\end{frame}
\begin{frame}[fragile] \frametitle{\texttt{git status}, the single most important command}
\begin{frame}[fragile] \frametitle{\texttt{git status}, one command to rule them all}
\lstinline{git status} displays the current state of the working
directory and the most relevant commands at the current state.
\footnotesize
......@@ -148,6 +148,22 @@ you@laptop$ git shortlog -s --no-merges | sort -nr | head -26
\end{itemize}
\end{frame}
\subsection{Other version control systems}
\begin{frame}
\frametitle{Numerous alternatives in two families}
See \href{https://en.wikipedia.org/wiki/Comparison_of_version-control_software}{Comparison of 35 version control software in Wikipedia}
\begin{description}
\item[Distributed:] Git, Mercurial, Bazaar, Darcs, Fossil, Arch (tla) etc.
\item[Client-server:] Propertary: ClearCase, Perforce; : SVN,
CVS, RCS, SCCS; etc.
\end{description}
\end{frame}
\section{Git init}
\begin{frame}[fragile]
\frametitle{Code: INIT 1/2}
......@@ -155,15 +171,18 @@ you@laptop$ git shortlog -s --no-merges | sort -nr | head -26
Create a simple repository with two files in 2 commits, one of the
file in a sub-directory.
\begin{minted}{bash}
mkdir MyRepo.git
cd MyRepo.git
git init .
touch myfile.txt
git hash-object myfile.txt # keep the SHA1 in mind
git add myfile.txt
git commit -m "first commit"
...
\footnotesize
\begin{minted}{console}
you@laptop$ mkdir MyRepo.git
you@laptop$ cd MyRepo.git
you@laptop$ git init .
you@laptop$ touch myfile.txt
you@laptop$ git hash-object myfile.txt # keep the SHA1 in mind
you@laptop$ git add myfile.txt
you@laptop$ git commit -m "first commit"
[master (commit racine) aac95f0] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 myfile.txt
\end{minted}
\end{exampleblock}
\end{frame}
......@@ -175,14 +194,19 @@ you@laptop$ git shortlog -s --no-merges | sort -nr | head -26
Create a simple repository with two files in 2 commits, one of the
file in a sub-directory.
\begin{minted}{bash}
...
mkdir Subdir
touch Subdir/mysubfile.txt
git add Subdir/mysubfile.txt
git commit -m "second commit"
git config --global alias.lg "log --all --graph --oneline" # Bonus
git lg
\footnotesize
\begin{minted}{console}
you@laptop$ mkdir Subdir
you@laptop$ touch Subdir/mysubfile.txt
you@laptop$ git add Subdir/mysubfile.txt
you@laptop$ git commit -m "second commit"
[master eee2e0b] second commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 Subdir/mysubfile.txt
you@laptop$ git config --local alias.lg "log --all --graph --oneline" # Bonus
you@laptop$ git lg
* eee2e0b (HEAD -> master) second commit
* aac95f0 first commit
\end{minted}
\end{exampleblock}
\end{frame}
......@@ -202,20 +226,55 @@ you@laptop$ git shortlog -s --no-merges | sort -nr | head -26
Let's explore the data model of \texttt{.git} !
\end{frame}
\begin{frame}[fragile]
\frametitle{Where is the last commit ? What does it contain ?}
\begin{exampleblock}{Data exploration 1/3}
\footnotesize
\begin{minted}{console}
you@laptop$ ls -F .git
branches/ COMMIT_EDITMSG config description HEAD hooks/ index info/ logs/ objects/ refs/
you@laptop$ cat .git/HEAD
ref: refs/heads/master
you@laptop$ cat .git/refs/heads/master
eee2e0b4bf68f4dc0e0f73bc6594736253206397
you@laptop$ ls .git/objects/
aa af b4 e2 e6 ee info pack
you@laptop$ ls .git/objects/ee
e2e0b4bf68f4dc0e0f73bc6594736253206397
\end{minted}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Where is the last commit ? What does it contain ?}
\begin{exampleblock}{Data exploration}
\begin{minted}{bash}
ls .git
cat .git/HEAD
cat .git/refs/heads/master
ls -lR .git/objects/
git cat-file -p SHA1_DE_MASTER
git cat-file -p SHA1_DE_TREE # Keep the SHA1 of myfile.txt
git cat-file -p SHA1_DE_SUBDIR
git cat-file -p SHA1_DE_subfile.txt # identical to SHA1 of subfile.txt
\begin{exampleblock}{Data exploration 2/3}
\footnotesize
\begin{minted}{console}
you@laptop$ git cat-file -p eee2e0b4bf68f4dc0e0f73bc6594736253206397 # ou eee2e
tree af6f7952b127efa16e7e60d3e39597107e3c19ce
parent aac95f06950b585f28c9027429fb806e22f55e30
author Grégory Mounié <Gregory.Mounie@imag.fr> 1578330554 +0100
committer Grégory Mounié <Gregory.Mounie@imag.fr> 1578330554 +0100
second commit
\end{minted}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Where is the last commit ? What does it contain ?}
\begin{exampleblock}{Data exploration 3/3}
\footnotesize
\begin{minted}{console}
you@laptop$ git cat-file -p af6f7952b127efa16e7e60d3e39597107e3c19ce
040000 tree e2aa7703c36797d761b847d5cf9bf70098487ce0 Subdir
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 myfile.txt
you@laptop$ git cat-file -p e2aa7703c36797d761b847d5cf9bf70098487ce0
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 mysubfile.txt
you@laptop$ git cat-file -p e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 # n'affiche rien
\end{minted}
\end{exampleblock}
\end{frame}
......@@ -657,17 +716,17 @@ Explain here WHY your change is good.
\frametitle{Dealing with the index}
\begin{itemize}
\item Commit only 2 files:
\begin{semiverbatim}
\begin{minted}{bash}
git add file1.txt
git add file2.txt
git commit # or git gui
\end{semiverbatim}
git commit # or git gui, magit ...
\end{minted}
\item Commit only some patch hunks:
\begin{semiverbatim}
\begin{minted}{bash}
git add -p
(answer yes or no for each hunk)
git commit # or git gui
\end{semiverbatim}
git commit # or git gui, magit ...
\end{minted}
\end{itemize}
\end{frame}
......@@ -1403,6 +1462,22 @@ Explain here WHY your change is good.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Master branch and visibility}
The \textbf{master} branch is the default branch in many tools and
settings. The Driessen's model highlights the results of the project
(public releases of the code).
\begin{alertblock}{Branching for software development studies}
When the goal is to highlight your software development history,
to get good grades, we advice the use of \textbf{master} as the
\em{develop} branch.
If you need a final result branch, you may call it \textbf{public}.
\end{alertblock}
\end{frame}
\begin{frame}
\frametitle{Concluding remarks}
......@@ -1430,10 +1505,11 @@ Explain here WHY your change is good.
\begin{itemize}
\item 3 places
\begin{itemize}
\item System-wide: \verb|/etc/gitconfig|
\item System-wide (``system''): \verb|/etc/gitconfig|
\item User-wide (``global''): \verb|~/.gitconfig| or
\verb|~/.config/git/config|
\item Per-repository: \verb|$project/.git/config|
\item Per-repository (``local'', default): \verb|$project/.git/config|
\item Per worktree (several checkout): \verb|$project/.git/config.worktree|
\end{itemize}
\item Precedence: per-repo overrides user-wide overrides
system-wide.
......
......@@ -3,8 +3,8 @@
#+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t
#+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
#+options: timestamp:t title:t toc:t todo:t |:t
#+title: Git: introduction
#+date: 2019
#+title: Git: introduction, basics, advanced
#+date: 2020-2021
#+author: Grégory Mounié
#+email: Gregory.Mounie@imag.fr
#+language: en
......@@ -16,9 +16,23 @@
1. [[* M1 Info: Git, niveau intermédiaire][Version française, M1 Info, niveau intermédiaire]]
2. [[* M1 MOSIG: Introduction to Git][English version, M1 MOSIG, beginner level]]
* M1 Info: Git, niveau intermédiaire
Le meilleur livre sur Git librement disponible
[[https://git-scm.com/book/en/v2]]
* Ensimag 2A: git avancé en 1h30
Pour aller plus loin, le meilleur livre sur Git est librement disponible
https://git-scm.com/book/en/v2
** Courte présentation technique sur git
- historique
- modèle de données
- branches
- configuration
- pour vidéoprojecteur :: http://systemes.pages.ensimag.fr/www-git/advanced1h30-slides.pdf
- en 4 parpage :: http://systemes.pages.ensimag.fr/www-git/advanced1h30-handout.pdf
* M1 Info: Introduction à Git
Le meilleur livre sur Git est librement disponible
https://git-scm.com/book/en/v2
Dans le reste de cette page, vous trouverez quelques exercices pour
comprendre les fondamentaux et les approfondir. Si vous êtes
......@@ -99,24 +113,25 @@
** Git and gitlab basics
*** Practical
Please replace, in the subject, http://gitlab.ensimag.fr by
http://gricad-gitlab.imag.fr if relevant, or at worse create your
http://gricad-gitlab.imag.fr if relevant, or create your
account on [[https://gitlab.com]]
- Default exercise: [[http://systemes.pages.ensimag.fr/www-git/git-computer-lab.pdf]]
- Beginner exercise: [[http://systemes.pages.ensimag.fr/www-git/git-computer-lab.pdf]]
- Sandbox (tar) for the exercise: [[http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/sandbox.tar.gz]]
# ** Practical 2: standalone git
** Git: under the hood
*** Practical
- Advanced exercise: [[http://systemes.pages.ensimag.fr/www-git/git-model-computer-lab.pdf]]
- (French version) [[http://recherche.noiraudes.net/resources/git/TP/tp1-modele-git.pdf]]
*** Explanations
- [[http://recherche.noiraudes.net/resources/git/Slides/understanding-git-slides.pdf]]
** Git: branches
*** Practical (in French)
[[http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git-bonus/tp1-flow.pdf]]
*** Explanations
[[http://recherche.noiraudes.net/resources/git/Slides/git-workflow-slides.pdf]]
** Git: under the hood
*** Practical (in French)
[[http://recherche.noiraudes.net/resources/git/TP/tp1-modele-git.pdf]]
*** Explanations
- [[http://recherche.noiraudes.net/resources/git/Slides/understanding-git-slides.pdf]]
** Git tools
[[http://recherche.noiraudes.net/resources/git/Slides/git-tools-slides.pdf]]
......
......@@ -44,10 +44,15 @@
\begin{document}
\maketitle
\thispagestyle{fancy}
\fancyhead[HL]{\includegraphics[height=2cm]{logo-uga-vo-cmjn.jpg}}
\fancyhead[HL]{\includegraphics[height=2cm]{logo_UGA_couleur_cmjn.jpg}}
\fancyhead[HC]{\includegraphics[height=2cm]{ensimag.jpg}}
\fancyhead[HR]{\includegraphics[width=4.5cm]{GINP_BlocLogo.png}}
This document is available here~:\\
\begin{center}
\url{http://systemes.pages.ensimag.fr/www-git/git-computer-lab.pdf}
\end{center}
An extended self-content french version of this document is available here~:\\
\url{http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/seance-machine-git.pdf}.
......
\documentclass[a4paper,10pt]{scrartcl}
\usepackage[frenchb]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\DeclareUnicodeCharacter{00A0}{~}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{microtype}
\usepackage{menukeys}
\usepackage{url}
\usepackage{hyperref}
\hypersetup{
colorlinks,
linkcolor={black},%{red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black},
linktoc=all
}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{calc,fadings,shapes.arrows,shadows,backgrounds, positioning}
% il exite mainteannt gitdags pour générer du tikz !
% \usepackage{gitdags}
\usepackage{fancyheadings}
\usepackage{minted}
\usepackage{todonotes}
\newcommand{\annee}{2020-2021}
\date{\annee}
\author{Sylvain Bouveret, Grégory Mounié}
\title{Git\\Fundamentals of the data model}
\sloppy
\usemintedstyle{tango}
\setminted{breaklines}
\setminted{linenos=true}
\definecolor{verylightgray}{rgb}{0.95,0.95,0.95}
\setminted{bgcolor=verylightgray}
\begin{document}
\maketitle
\thispagestyle{fancy}
\fancyhead[HL]{\includegraphics[height=2cm]{logo_UGA_couleur_cmjn.jpg}}
\fancyhead[HC]{\includegraphics[height=2cm]{ensimag.jpg}}
\fancyhead[HR]{\includegraphics[width=4.5cm]{GINP_BlocLogo.png}}
This document is available here:\\
\begin{center}
\url{http://systemes.pages.ensimag.fr/www-git/git-model-computer-lab.pdf}
\end{center}
\section{Introduction}
\subsection{Git: plumbing}
At first sight, Git is a complicated beast. It uses roughly 100
commands, some with tenths of options. But Git has a simple data
model. Indeed, it has a classical file hierarchy storing multiple
version of the content and the commands to manipulate these
files. Understanding the basics of the model greatly ease the
understanding of the majority of the commands and the efficient
management of the repositories.
The exercises will look at the commits, the branches, the tags and
most of the basic command effect.
\subsection{Team organization}
These exercises can be done alone. We advise to do it in team of
two. Each member of the team will do all the commands. Thus, each
member should explain to the other its understanding. Exchanging with
your teammate will force you to slow your pace and consider all the
details more carefully.
Let us look now at the content of the \texttt{.git} directory.
\section{First steps}
You will create first a small python program to uncompress ZLIB file,
then a minimalist repository.
\subsection{ZLIB cat in python}
The goal of the following program is to show you that Git use plain
Zlib compression format. Thus, the file contents are easily readable. Zlib
is part of the standard library of libpng, python or Java and a
ubiquitous compression format (cf. https://en.wikipedia.org/wiki/Zlib)
The code can be directly downloaded from
\url{http://recherche.noiraudes.net/resources/git/TP/zlibcat.py3})
\inputminted{python}{../FormaContinue_MeteoNov2017/TPs/zlibcat.py3}
Do not forget to set its execution right after the edition.
\begin{minted}{console}
$ emacs zlibcat.py3 # or your favorite editor
$ chmod u+x zlibcat.py3
\end{minted}
\subsection{Minimalist repository}
Create a minimalist repository \mintinline{console}{MiniRepo} with a
single file and a first commit.
\begin{minted}{console}
$ mkdir MiniRepo
$ cd MiniRepo
$ git init .
$ emacs file.txt # add few lines with your editor
$ git add file.txt
$ git commit -m "message 1"
\end{minted}
\section{Exploring the .git directory}
\label{sec=gitrepo}
Check the files into the repository:
\begin{minted}{console}
$ ls -F .git
\end{minted}
You should find a file \texttt{HEAD}. Read its content.
The current state of the working directory (HEAD) is written in the
\texttt{HEAD} file. Following the value in the \texttt{refs/}
directory, find the file content with the SHA-1 variable of the head
and note its value.
First check that the value of the SHA-1 is the same as the commit.
\begin{minted}{console}
$ git log
\end{minted}
\subsection{From SHA-1 to SHA-256}
Git is moving, very slowly and carefully, from SHA-1 hash to SHA-256
hash to evade from the vulnerabilities of SHA-1.
\section{Content-addressable storage: the \texttt{objects/} directory}
\subsection{First, by hand}
In the \texttt{objects/} directory, you should find a directory with a
name of two characters, the first two characters of the SHA-1.
In this directory, you should find a file, with a name composed of the
remaining character of the SHA-1.
Display the content of the file using \texttt{zlibcat.py3} with a
command similar to:
\begin{minted}{console}
$ ./zlibcat.py3 < .git/objects/2d/447e8255ace8f0d36527aa62ab7669f121f540
\end{minted}
Note the SHA-1 of the \texttt{tree}. Using the same procedure, display
the content of the \texttt{tree} with \texttt{zlibcat.py3}.
The tree format is slightly more complicated. Yet, only one unread
file remain in \texttt{objects/}. Check that the last file content is
the content of \texttt{file.txt}.
\subsection{Second, using Git}
Git provides directly a tool to read the content of file given the SHA-1 value.
\begin{minted}{console}
$ git cat-file -p THE_SHA-1_FILE_NAME_TO_READ
\end{minted}
Redo the full chain from \texttt{HEAD} to \texttt{file.txt} using
\texttt{cat-file}.
\subsection{Trees}
Write a subdirectory, new file in it, with the same name, but
different content, and register the file in a new commit.
\begin{minted}{console}
$ mkdir subDir
$ emacs subDir/file.txt # insert few lines
$ git add subDir/file.txt
$ git commit -m "message 2"
\end{minted}
Following again the path of \mintinline{sh}{git cat-file -p}, read the
\texttt{tree}. It contents now a reference to another tree (the
subdirectory). The subdirectory tree reference the new file. Check the
content of the new file.
\subsection{Duplicates}
Copy the first file and register the copy.
\begin{minted}{console}
$ cp file.txt file_copy.txt
$ git add file_copy.txt
$ git commit -m "message 3"
\end{minted}
Following again the path of \mintinline{sh}{git cat-file -p}, read the
\texttt{tree}. Check that the blob are the same for both files (same
SHA-1, thus same file).
\section{Delta storage}
Modify slightly the content of \texttt{file.txt}. Commit the modification.
Check that a new blob appear. Both blob should have very similar data
in them.
Ask Git to optimize the storage:
\begin{minted}{console}
$ git gc
\end{minted}
A new \texttt{pack} file (and \texttt{.idx}) is now present in the
\texttt{objects/pack/} directory. This pack file includes the file
contents with delta. The following command allow to display the table
of content of the pack:
\begin{minted}{console}
git verify-pack -v .git/objects/pack/pack-0618531a948d3537443496da7765fb4d0b4fb74f
\end{minted}
The pack contains the last value of the file and the delta to come
back in the file history.
\section{The tags in the \texttt{refs/} directory}\label{sec:tags}
The tags are given to a particular commit in order to find them again
later. They are quite similar to branches but never move their head
after their creation.
Create a tag on the current commit:
\begin{minted}{console}
$ git tag v0.1
\end{minted}
A new file appears in the \texttt{.git/refs/tags}. Its content should
be the same as the current HEAD:
\begin{minted}{console}
cat .git/refs/tags/v0.1
\end{minted}
Now, move forward the \texttt{master} branch:
\begin{minted}{console}
$ emacs file2.txt # insert few lines
$ git add file2.txt
$ git commit -m "message 4"
\end{minted}
Check that the tag do not move.
\section{Branches}
Create a new branch \texttt{develop}, copy a file and commit.
\begin{minted}{console}
$ git checkout -b develop
$ cp file.txt file_copy2.txt
$ git add file_copy2.txt
$ git commit -m "message dev1"
\end{minted}
Check that HEAD points on the right commit of the \texttt{develop} branch.
Then, come back on the \texttt{master} branch and do exactly the same
modification.
\begin{minted}{console}
$ git checkout master
$ cp file.txt file_copy2.txt
$ git add file_copy2.txt
$ git commit -m "message 5"
\end{minted}
Check that HEAD points on the right commit of the \texttt{master} branch.