-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart1.Rmd
128 lines (77 loc) · 4.25 KB
/
part1.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
---
title: "Part 1: Version control"
output:
html_document:
theme: simplex
toc: false
toc_depth: 3
highlight: espresso
---
# What is version control
<div style="text-align: center;">
<table>
<col width="40%">
<col width="40%">
<tr>
<td style="text-align: left;">
[I]s the <strong>management of changes</strong> to documents [...] <strong>Changes are usually identified</strong> by a number or letter code, termed the "revision number", "revision level", or simply "revision". For example, an initial set of files is "revision 1". When the first change is made, the resulting set is "revision 2", and so on. <strong>Each revision is associated with a timestamp and the person making the change</strong>. Revisions can be <strong>compared</strong>, <strong>restored</strong>, and with some types of files, <strong>merged</strong>. -- <a href="https://en.wikipedia.org/w/index.php?title=Version_control&oldid=948839536" target="_blank">Wiki</a>
</td>
<td>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/af/Revision_controlled_project_visualization-2010-24-02.svg" alt="Diagram of version control" width="35%">
</td>
</tr>
</table>
</div>
---
# Why do we care
Have you ever:
- Made a **change to code**, realised it was a **mistake** and wanted to **revert** back?
- **Lost code** or had a backup that was too old?
- Had to **maintain multiple versions** of a product?
- Wanted to see the **difference between** two (or more) **versions** of your code?
- Wanted to prove that a particular **change broke or fixed** a piece of code?
- Wanted to **review the history** of some code?
- Wanted to submit a **change** to **someone else's code**?
- Wanted to **share your code**, or let other people work on your code?
- Wanted to see **how much work** is being done, and where, when and by whom?
- Wanted to **experiment** with a new feature **without interfering** with working code?
In these cases, and no doubt others, a version control system should make your life easier.
-- [Stackoverflow](https://stackoverflow.com/a/1408464/2097171) (by [si618](https://stackoverflow.com/users/44540/si618))
---
# Git: The stupid content tracker
<div style="text-align: center;">
<figure>
<a href="https://commons.wikimedia.org/wiki/File:Git-logo.svg" target="_blank"><img style="width: 200px;vertical-align: middle;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Git-logo.svg/500px-Git-logo.svg.png" hspace="20px" alt="Git logo"></a>
</figure>
</div>
- During this class (and perhaps, the entire program) we will be using [Git](https://git-scm.com).
- Git is used by [most developers in the world](https://insights.stackoverflow.com/survey/2018#work-_-version-control).
- A great reference about the tool can be found [here](https://git-scm.com/book)
- More on what's stupid about git [here](https://en.wikipedia.org/wiki/Git#Naming).
---
# How can I use Git
There are several ways to include Git in your work-pipeline. A few are:
- Through command line
- Through one of the available Git GUIs:
- RStudio [(link)](https://rstudio.com/products/rstudio/features/)
- Git-Cola [(link)](https://git-cola.github.io/)
- Github Desktop [(Link)](https://desktop.github.com/)
More alternatives [here](https://git-scm.com/download/gui).
---
# A Common workflow
<div style="text-align: center;">
<figure>
<img style="width:600px;vertical-align:middle;" hspace="20px" src="https://github.com/USCbiostats/PM566/raw/b9ca589471562011f57d08845825282ee19d6acb/static/slides/02-version-control/fig/git.svg" alt="Git workflow">
</figure>
<figcaption><b>A common git workflow</b></figcaption>
</div>
1. Start the session by pulling (possible) updates: `git pull`
2. Make changes
a. (optional) Add untracked (possibly new) files: `git add [target file]`
b. (optional) Stage tracked files that were modified: `git add [target file]`
c. (optional) Revert changes on a file: `git checkout [target file]`
3. Move changes to the staging area (optional): `git add`
4. Commit:
a. If nothing pending: `git commit -m "Your comments go here."`
b. If modifications not staged: `git commit -a -m "Your comments go here."`
5. Upload the commit to the remote repo: `git push`.