-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.Rmd
446 lines (369 loc) · 11.7 KB
/
github.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
---
title: 'Using `r icons::fontawesome("git-square")` with `r icons::fontawesome("r-project")`'
#subtitle: "slides : [https://tinyurl.com/2s4antdy](https://tinyurl.com/2s4antdy)"
author: "Maxime Jaunatre"
institute: "LESSEM | INRAE"
date: "2022-12-01 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
css: [default, metropolis, metropolis-fonts]
nature:
highlightStyle: github
highlightLines: true
highlightSpans: true
countIncrementalSlides: false
seal: false
---
```{r setup, include=FALSE}
library(knitr)
library(emo)
library(icons)
options(htmltools.dir.version = FALSE, knitr.duplicate.label = 'allow')
knitr::opts_chunk$set(fig.align = "center", eval = FALSE)
```
```{r, eval = FALSE, include = FALSE}
# This are the dependencies to compile this rmd.
remotes::install_github("mitchelloharawild/icons")
icons::download_fontawesome()
remotes::install_github("hadley/emo")
```
exclude: true
class: inverse, center, middle
# Introduction
---
exclude: true
# Utilisation de Git dans un travail avec R
**Résumé :**
---
class: inverse, center, middle
# Remote repository : Github
---
# Working with others
```{r bordel, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache= TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
column 4/.style = { nodes = { empty } },
]
{
& & & \\
% A.txt & A.txt & A.txt & \\
A1.txt & A1'.txt & A1''.txt & \\
A2.txt & A2'.txt & & B.txt \\
A2.txt & & B1.txt & B1'.txt \\
& C.txt & B2.txt & \\
& D.txt & & \\
};
\node[fit=(m-1-1)(m-1-1)]{Etno P.};
\node[fit=(m-1-2)(m-1-2)]{Gorgious K.};
\node[fit=(m-1-3)(m-1-3)]{Candy H. C.};
\node[fit=(m-1-4)(m-1-4)]{Bud B.};
\draw [arrow] (m-2-1) -- (m-3-1);
\draw [arrow] (m-3-1) -- (m-4-1);
\draw [arrow] (m-4-1) -- (m-5-2);
\draw [arrow] (m-2-2) -- (m-3-2);
\draw [arrow] (m-3-2) -- (m-4-1);
\draw [arrow] (m-5-2) -- (m-6-2);
\draw [arrow] (m-2-3) -- (m-3-4);
\draw [arrow] (m-4-3) -- (m-5-3);
\draw [arrow] (m-4-3) -- (m-5-2);
\draw [arrow] (m-5-3) -- (m-6-2);
\draw [arrow] (m-3-4) -- (m-4-4);
\draw [arrow] (m-3-4) -- (m-4-3);
\draw [arrow] (m-4-4) -- (m-5-3);
\end{tikzpicture}
```
It becomes complex very quickly... 12 versions of a single file?
---
# Using a remote repository
Git is installed on your computer, and a repository in your folder.
Principle of **Cloud** : installation of Git on a server and copy of the repository.
Several hosters exist:
**Github** (Microsoft) `r icons::fontawesome("github")`
**Bitbucket** `r icons::fontawesome("bitbucket")`
**Gitlab** `r icons::fontawesome("gitlab")`
And the list is long: [https://git.wiki.kernel.org/index.php/GitHosting](https://git.wiki.kernel.org/index.php/GitHosting)
It is possible to copy a repository on several hosts (mirroring) !
*You can even have a remote on the same computer, or on an external disk ! For example another disk...but the reality is a bit more complex.*
---
# Gorgious's repository
**Repo** : github.com/Gorgious/name
```{r github, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache= TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
& 7f21c09 & \\
& d39ac60 & \\
& c78c64d & \\
& & \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-2) -- (m-\j-2);
}
\end{tikzpicture}
```
---
# Clone a remote
```{r clone, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache= TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
& 7f21c09 & 7f21c09 \\
& d39ac60 & d39ac60 \\
& c78c64d & c78c64d \\
& & \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-2) -- (m-\j-2);
\draw [arrow] (m-\i-3) -- (m-\j-3);
}
\end{tikzpicture}
```
---
# Local commit
```{r local, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache= TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
& 7f21c09 & 7f21c09 \\
& d39ac60 & d39ac60 \\
& c78c64d & c78c64d \\
& & |[high]| cbdac1e \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-2) -- (m-\j-2);
\draw [arrow] (m-\i-3) -- (m-\j-3);
}
\draw [harrow] (m-4-3) -- (m-5-3);
\end{tikzpicture}
```
---
# Push
```{r push, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache= TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
& 7f21c09 & 7f21c09 \\
& d39ac60 & d39ac60 \\
& c78c64d & c78c64d \\
& |[high]| cbdac1e & |[high]| cbdac1e \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-2) -- (m-\j-2);
\draw [arrow] (m-\i-3) -- (m-\j-3);
}
\draw [harrow] (m-4-2) -- (m-5-2);
\draw [harrow] (m-4-3) -- (m-5-3);
\end{tikzpicture}
```
---
# Late
```{r retard, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache=TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
7f21c09 & 7f21c09 & 7f21c09 \\
d39ac60 & d39ac60 & d39ac60 \\
c78c64d & c78c64d & c78c64d \\
& cbdac1e & cbdac1e \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-1) -- (m-\j-1);
\draw [arrow] (m-\i-2) -- (m-\j-2);
\draw [arrow] (m-\i-3) -- (m-\j-3);
}
\draw [arrow] (m-4-2) -- (m-5-2);
\draw [arrow] (m-4-3) -- (m-5-3);
\end{tikzpicture}
```
---
# Pull
```{r pull, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache = TRUE}
\begin{tikzpicture}
\matrix (m)
[
matrix of nodes,
nodes in empty cells,
column sep = 3em,
row sep = 5ex,
column 1/.style = { nodes = { empty } },
column 2/.style = { nodes = { empty } },
column 3/.style = { nodes = { empty } },
]
{
& & \\
7f21c09 & 7f21c09 & 7f21c09 \\
d39ac60 & d39ac60 & d39ac60 \\
c78c64d & c78c64d & c78c64d \\
|[high]| cbdac1e & cbdac1e & cbdac1e \\
};
\node[fit=(m-1-1)(m-1-1)]{Collaborator};
\node[fit=(m-1-2)(m-1-2)]{Github};
\node[fit=(m-1-3)(m-1-3)]{Local};
\foreach \i/\j in {2/3, 3/4} {
\draw [arrow] (m-\i-1) -- (m-\j-1);
\draw [arrow] (m-\i-2) -- (m-\j-2);
\draw [arrow] (m-\i-3) -- (m-\j-3);
}
\draw [arrow] (m-4-2) -- (m-5-2);
\draw [arrow] (m-4-3) -- (m-5-3);
\draw [harrow] (m-4-1) -- (m-5-1);
\end{tikzpicture}
```
---
# COMMIT -> PULL -> PUSH
```{r pull_push_diag, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache = TRUE}
\begin{tikzpicture}[block/.style={draw,fill=strange,minimum height=2.5em},
font=\sffamily,>=stealth]
\begin{scope}[start chain=A going below,node distance=1em,
local bounding box=buffers]
\node[block,minimum width=6em](remote){Remote github};
\node[right= 8em of remote, block,minimum width=6em](local){Fichiers};
\end{scope}
\node[below= 6em of buffers,align=center, block,minimum width=6em](repo){Repository \\Git local};
%\draw[->, thick](remote) edge[bend left] node[midway, fill=white]{Pull} (local);
\draw[->, thick](remote) edge[bend left] node[midway, fill=white]{Pull} (repo);
%\draw[->, thick](remote) edge[dashed] node[midway, fill=white]{Fetch} (repo);
\draw[->, thick](remote) edge node[midway, fill=white]{Clone} (local);
\draw[->,thick](local) edge[bend left] node[midway, fill=white]{Add} (repo);
\draw[->,thick](repo) edge[bend left] node[midway, fill=white]{Push} (remote);
\draw[->,thick](repo) edge[loop right] node[midway, fill=white]{Commit} (repo);
\end{tikzpicture}
```
---
# Conflits : DON'T PANIC
A conflict occurs when several people modify the same document in the same place.
Most of the time git handles the differences (**merge**) alone. It requires the intervention of a user in case of impossible choice.
.pull-left[
```{bash, echo = TRUE}
# Commit d39ac60
x <- "Hi"
- x <- paste(x,"this is a file")
+ x <- paste(x,"this is a great file")
cat(x)
```
```{bash, echo = TRUE}
# Commit cbdac1e
x <- "Hi"
- x <- paste(x,"this is a file").
+ x <- paste(x,"this is a boring file")
cat(x)
```
]
--
.pull-right[
```{bash, echo = TRUE}
x <- "Hi"
*<<<<<<< HEAD:file.R
*+ x <- paste(x,"this is a great file")
*=======
*+ x <- paste(x,"this is a boring file")
*>>>>>>> main:File.R
cat(x)
```
We need to edit by hand (solve the conflict) and commit.
]
It's important here to have someone in charge of the main repository.
---
# Alternative : branches
Be able to test things on a parallel history to make sure you don't break anything.
```{r branches, engine='tikz', fig.ext = 'png', engine.opts = list(template = "tex/gitdags.tex"), echo = FALSE, eval=TRUE, cache = TRUE}
\begin{tikzpicture}
\gitDAG[grow right sep = 2em]{
A -- B -- {
C,
{D -- E },
}
};
% Remote branch
\gitremotebranch
[origmaster] % node name
{origin/master} % node text
{above=of C} % node placement
{C} % target
% Branch
\gitbranch
{dev} % node name and text
{above=of E} % node placement
{E} % target
% HEAD reference
\gitHEAD
{above=of dev} % node placement
{dev} % target
\end{tikzpicture}
```
**HEAD** : current status of the files.
*master* et *dev* : branch names