-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-doc.html
More file actions
280 lines (243 loc) · 7.78 KB
/
git-doc.html
File metadata and controls
280 lines (243 loc) · 7.78 KB
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
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8"/>
<title>cpoli</title>
<link rel="stylesheet" href="main.css" >
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Droid+Serif">
<link rel="shortcut icon" href="images/cp.ico">
</head>
<body id="body">
<id id="black-strip">
</id>
<div id="top_menu">
<ul>
<li><a href="index.html"><div class="home">Home</div></a></li>
<li><a href="publi.html"><div class="publi">lications</div></a></li>
<li><a href="thesis.html"> <div class="thesis">sis</div></a></li>
<li><a href="vitae.html"> <div class="vitae">ef vitae</div></a></li>
<li><a href="prog.html"><div class="prog">gramming</div></a></li>
</ul>
</div>
<header id=top_header>
<h1> Charles Poli, PhD </h1>
<h2>Head of Artificial Intelligence, </br>
Cambridge Quantum Computing Limited, London.</h2>
</header>
<div id="big_wrapper">
<img src="images/git.png" height="120px" style="margin-left:250px;">
<article>
<header><h1> <a name="doc"></a> <b> <div class="git">: a super short documentation </b></h1></header>
</br>
Git is a distributed revision control system, it allows to:
<ul>
<li> keep track of the changes. </li>
<li> find out what has been changed.</li>
<li> store the project at desired moments in time (i.e. perform backups - produce project versions).</li>
<li> recover an earlier version.</li>
</ul>
To do so, Git stores the different versions of your project in a repository located in your project directory.
</br></br>
<h1> Installation </h1>
</br>
Visit the website <a href="http://git-scm.com">http://git-scm.com</a>
to download Git and find the complete documentation. </br>
During the installation, select Git from Git bash only. When this is done, </br>
for Mac/Linux:</br>
launch a Terminal.</br>
for Windows: </br>
menu → Git → Git Bash</br>
</br></br>
<header> <h1> Create a Git account </h1> </header>
<div class="shell-wrap">
<ul class="shell-body">
<li>git config --global user.name "Alex Dumas"</li>
<li>git config --global user.email ”alex@dumas.fr”</li>
</ul>
</div>
<h1> Git commands </h1>
</br>
<h2>initialize Git</h2>
</br>
Go to the project directory using Terminal/Powershell:
<div class="shell-wrap">
<ul class="shell-body">
<li>cd project </li>
<li>git init</li>
</ul>
</div>
The last command will create a hidden Git repository.
</br></br>
<h2>First backup (commit)</h2>
</br>
The first commit is done in 2 steps:
<div class="shell-wrap">
<ul class="shell-body">
<li>git add .</li>
<li>git commit -m ”first comments”</li>
</ul>
</div>
The first command sends the files from the Working area to the Staging area. </br>
The second command sends the files from the Staging area to the Repository. </br>
</br>
<h2> Next commits</h2>
<div class="shell-wrap">
<ul class="shell-body">
<li>git commit -am ”new comments”
</li>
</ul>
</div>
</br>
<h2> Useful commands </h2>
</br>
Check the difference between the working copy and the repository.
<div class="shell-wrap">
<ul class="shell-body">
<li>git status</li>
</ul>
</div>
Get commit history
<div class="shell-wrap">
<ul class="shell-body">
<li>git log</li>
</ul>
</div>
Delete a Git project
<div class="shell-wrap">
<ul class="shell-body">
<li>rm -rf .git</li>
</ul>
</div>
<h2> An Example </h2>
<br>
creation of a folder containing a very simple file:
<div class="shell-wrap">
<ul class="shell-body">
<li>mkdir git-test
<li>cd git-test
<li>emacs file.txt
</div>
File.txt:
<div style="border:3px solid black; margin: 30px 355px 30px 80px; ">
one line
</div>
Git initialization
<div class="shell-wrap">
<ul class="shell-body">
<li> git init <br>
Initialized empty Git repository in /Users/adumas/git-test/.git/<br>
</div>
Git first commit
<div class="shell-wrap">
<ul class="shell-body">
<li> git add . </li>
<li>git commit -m "first commit: 1 text file" </li>
[master (root-commit) 209f961] first commit: 1 text file<br>
1 file changed, 1 insertion(+)<br>
create mode 100644 file.txt<br>
</div>
check the repository
<div class="shell-wrap">
<ul class="shell-body">
<li>git log</li>
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b<br>
Author: Alex Dumas "alex@dumas.fr"<br>
Date: Sat May 16 17:27:06 2015 +0100
</br>
first commit: 1 text file<br>
</ul>
</div>
modification the text file </br>
<div style="border:3px solid black; margin: 30px 355px 30px 80px; ">
first line </br>
second line </br>
third line </br>
</div>
check the difference between the working area and the repository:
<div class="shell-wrap">
<ul class="shell-body">
<li>git diff file.txt</li>
diff --git a/file.txt b/file.txt </br>
index e3c0674..ae0d792 100644</br>
--- a/file.txt</br>
+++ b/file.txt</br>
@@ -1 +1,3 @@</br>
-one line</br>
+first line</br>
+second line</br>
+third line</br>
</ul>
</div>
Commit the new file
<div class="shell-wrap">
<ul class="shell-body">
<li> git commit -am "second commit: 3 lines"</li>
[master e869c09] second commit: 3 lines <br>
1 file changed, 3 insertions(+), 1 deletion(-) <br>
</ul>
</div>
Check the commits history
<div class="shell-wrap">
<ul class="shell-body">
<li> git log</li>
commit e869c09ec49f611828ac45d48a5ea1106a806ac4 <br>
Author: Alex Dumas "alex@dumas.fr"<br>
Date: Sat May 16 17:28:57 2015 +0100<br>
second commit: 3 lines<br>
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b<br>
Author: Alex Dumas "alex@dumas.fr"<br>
Date: Sat May 16 17:27:06 2015 +0100<br>
first commit: 1 text file<br>
</ul>
</div>
Note that a tracking number is associated to each commit: </br></br>
the first commit has the tracking number:</br>
209f961f9c8cfaad8f5689d354faa240ee161f7b</br>
</br>
the second commit has the tracking number: </br>
e869c09ec49f611828ac45d48a5ea1106a806ac4</br>
</br>
Now, let's go back to the first commit:
<div class="shell-wrap">
<ul class="shell-body">
<li>git checkout 209f961f9c8cf -- file.txt </li>
<li># note that the full tracking number is not needed </li>
</ul>
</div>
Commit the new version
<div class="shell-wrap">
<ul class="shell-body">
<li>git commit -am "third commit: going back to first commit"</li>
</ul>
</div>
Last check of the commits history
<div class="shell-wrap">
<ul class="shell-body">
<li> git log </li>
commit 7cd3dc1a4c2bf9a974231c666f0c5b9b0ae49987</br>
Author: Alex Dumas "alex@dumas.fr"</br>
Date: Sat May 16 17:30:34 2015 +0100</br>
third commit: going back to first commit</br>
commit e869c09ec49f611828ac45d48a5ea1106a806ac4</br>
Author: Alex Dumas alex@dumas.fr</br>
Date: Sat May 16 17:28:57 2015 +0100</br>
second commit: 3 lines</br>
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b</br>
Author: Alex Dumas alex@dumas.fr</br>
Date: Sat May 16 17:27:06 2015 +0100</br>
first commit: 1 text file
</ul>
</div>
<footer id="thefooter">
<small>© Copyright cpoli 2014</small>
</footer>
</body>
</html>
<!--
<div class="shell-wrap">
<ul class="shell-body">
<li>cd /Users/project </li>
<li>git init</li>
</ul>
</div>
-->