-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-notes.txt
346 lines (251 loc) · 7.04 KB
/
git-notes.txt
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
- - - Unix Commands - - -
pwd print working directory ;
displays the absolute path to where you are
cd change directory :
navigates to a different directory
+ arguments :
absolute or relative path
no argument will go back to home
.. goes one filesystem up (can be chained ../..)
ls list :
lists the contents of the present working directory
+ flags :
-t : sorts by modification time
-l : shows in a long format
-r : reverses the order
-a : shows all files, even hidden ones
-d : lists a directory, not its contents
+ arguments :
path a directory
no argument lists current directory
man manual :
prints out a manual for any command
+ arguments :
any command
touch :
change file access and modification times
creates a file if it doesn’t exist
+ arguments
file name
mkdir make directory :
creates a directory
+ flags
-p creates a directory tree as many deep as you specify
history :
provides a history of commands
+ arguments
integers give you a list of the -- most recent commands
less :
allows user to control movement through the reading of a file
head :
displays the beginning of a file
+ flags
-n +int shows the first int lines of a file
mv move :
moves a file to a new location (is also used for renaming files)
+ arguments
file location
nano
text editor
cat concatenate :
prints a file to the shell / concatenates two files together
+ arguments
file names
cp copy :
copies a file or directory
+ arguments
file / directory to be copied
new file / directory name
+ flags
-r (recursive) allows directories to be copied
rm remove :
removes a file / directory
+ arguments
file / directory to be removed
+ flags
-r (recursive) allows directories to be copied
whoami :
returns the name of the current user
adduser :
(must be done in sudo in Linux) adds a new user
su switch user :
switches between users
exit :
exits out of a switched user
chmod change mode :
changes permissions (mode) for a file / directory
+arguments
u/g/o (user / group / other) +/- r/w /x (read / write / execute)
ex: u-x
ex: ugo+x
rwx notation (r = 4, w = 2, x = 1) ugo
ex: 644
chown change owner :
changes the owner of a file / directory
must be done in sudo
+arguments
new-user:new-group file-name (chown colincoltrera tester.txt)
top :
displays running processes and resources used
ps processes :
lists out running processes
+option
aux
lists all processes running on a machine
grep :
searches for a pattern in an input, filters only lines with that pattern
fg foreground :
resumes a stopped job
+arguments
job number (can be seen with jobs)
jobs :
returns a list of processes in current session
kill :
kills a process, using its process ID (sends a TERM signal)
with option, sends signal to a process
+options
-TERM sends a normal TERM signal
-KILL / -SIGKILL / -9 forces the killing of a process (dangerous)
-STOP stops a process, can be restarted later
rmdir remove directory :
removes an empty directory
- - - - - -
| pipe :
pipes first command output to next command
history | less
> redirection operator :
makes output a new file
history > terminal-history.txt
>>
adds to the end of an existing file
history >> old-file.txt
!!
runs / fills in the previous command
sudo super user do :
runs a command as the super user (root user)
&
use after a job command to open the job in the background (ex: top &)
*
wildcard representing zero or more characters
?
wildcard representing a single character
[]
wildcard representing a range of characters
[dte] one character d, t, or e
[0-9] one number 0 through 9 inclusive
[^a-k] one letter not a-k
- - - - - -
ctr+z
stops a job, which can be restarted later (sends a STOP signal to process)
ctr+c
kills a job (sends the TERM signal to process)
- - - Git Commands - - -
git config
change / display email and username, etc.
git init
initializes a repository in a directory
git status
shows the status of current save repo (branch , untracked files)
git add
adds a file to the staging area
git commit
commits files from the staging area to the repo
makes a permanent record of changes
changes made
identity of changer
date and time
brief message
universally unique ident for changes
+ flags
-m to add a message (speak in the present tense)
-a skips the staging area and commits all files
git log
logs git history
git branch
adds branch label where the HEAD is pointing, or shows the branch
+ argument
label
git checkout
changes where the HEAD is pointing
git remote add origin https://github.com/ccoltrera/uge-workshop.git
git remote -v
verbose
git push -u origin master
(-u sets the preferences for a branch)
git branch -d git-notes
deletes a branch, will not be possible if master doesn’t have changes
(can use -D if branch changes not in master)
- - - Notes - - -
Paths
Paths that start with a / are absolute
Root
topmost container of a filesystem
generally restricted to admin users
never delete anything located directly in the root
var
for things that change regularly (like logs)
etc
for files that don’t change regularly
tmp
for temporary files, gets deleted regularly
Flags
modify how commands work
can be combined together ( -lt , -tl , -l -t , -t -l)
Naming
separate words with - , _ , or with “camel spacing” (myFolder)
don’t use spaces, because they can be a bitch in UNIX
Linux is case sensitive, OSX is case insensitive (commands are, however)
Pipe ( | )
chains commands together
outputs the first command and uses it as input to the second
Hidden files
files that begin with a dot (.) are default hidden
‘Dirtying the directory’
anything that makes the working directory and repo different
Process
an instance of a program
Job
a process that you own
Signal
a message sent to a process by the operating system
** Git only changes files it’s tracking. Files changed in the working directory that aren’t in the repo won’t be affected by git
- - - Git Directories - - -
$git status
Working directory Staging area Repo
----------------- ------------ ----
unix_notes.txt
$git add unix_notes.txt
Working directory Staging area Repo
----------------- ------------ ----
unix_notes.txt unix_notes.txt
$git commit -m ‘add unix notes’
Working directory Staging area Repo
----------------- ------------ ----
unix_notes.txt unix_notes.txt
- - - Visualizing Git - - -
$git init
[A]
^master
^HEAD
$git commit
[A]——————————[B]
^master
^HEAD
$git branch git-notes
[A]——————————[B]
^master
^HEAD
^git-notes
$git checkout git-notes
$git commit
[A]——————————[B]——————————[C]
^master ^HEAD
^git-notes
$git checkout master
$git commit
[A]——————————[B]——————————[C]
| ^git-notes
|
[D]
^master
^HEAD