@@ -23,8 +23,8 @@ or intermediate files created during data analysis?
23
23
Let's create a few dummy files:
24
24
25
25
``` bash
26
- $ mkdir receipts
27
- $ touch a.png b.png c.png receipts/a .jpg receipts/b .jpg
26
+ $ mkdir pictures
27
+ $ touch a.png b.png c.png pictures/cake1 .jpg pictures/cake2 .jpg
28
28
```
29
29
30
30
and see what Git says:
@@ -41,7 +41,7 @@ Untracked files:
41
41
a.png
42
42
b.png
43
43
c.png
44
- receipts /
44
+ pictures /
45
45
46
46
nothing added to commit but untracked files present (use "git add" to track)
47
47
```
@@ -61,7 +61,7 @@ Type the text below into the `.gitignore` file:
61
61
62
62
```
63
63
*.png
64
- receipts /
64
+ pictures /
65
65
```
66
66
67
67
Save the file and exit your editor.
@@ -74,11 +74,11 @@ $ cat .gitignore
74
74
75
75
``` output
76
76
*.png
77
- receipts /
77
+ pictures /
78
78
```
79
79
80
80
These patterns tell Git to ignore any file whose name ends in ` .png `
81
- and everything in the ` receipts ` directory.
81
+ and everything in the ` pictures ` directory.
82
82
(If any of these files were already being tracked,
83
83
Git would continue to track them.)
84
84
@@ -107,7 +107,7 @@ Let's add and commit `.gitignore`:
107
107
108
108
``` bash
109
109
$ git add .gitignore
110
- $ git commit -m " Ignore png files and the receipts folder."
110
+ $ git commit -m " Ignore png files and the pictures folder."
111
111
$ git status
112
112
```
113
113
@@ -145,7 +145,7 @@ Ignored files:
145
145
a.png
146
146
b.png
147
147
c.png
148
- receipts /
148
+ pictures /
149
149
150
150
nothing to commit, working tree clean
151
151
```
@@ -157,27 +157,27 @@ nothing to commit, working tree clean
157
157
Given a directory structure that looks like:
158
158
159
159
``` bash
160
- receipts/data
161
- receipts/plots
160
+ pictures/cake
161
+ pictures/pizza
162
162
```
163
163
164
- How would you ignore only ` receipts/plots ` and not ` receipts/data ` ?
164
+ How would you ignore only ` pictures/cake ` and not ` pictures/pizza ` ?
165
165
166
166
::::::::::::::: solution
167
167
168
168
## Solution
169
169
170
170
If you only want to ignore the contents of
171
- ` receipts/plots ` , you can change your ` .gitignore ` to ignore
172
- only the ` /plots / ` subfolder by adding the following line to
171
+ ` pictures/cake ` , you can change your ` .gitignore ` to ignore
172
+ only the ` /cake / ` subfolder by adding the following line to
173
173
your .gitignore:
174
174
175
175
``` output
176
- receipts/plots /
176
+ pictures/cake /
177
177
```
178
178
179
- This line will ensure only the contents of ` receipts/plots ` is ignored, and
180
- not the contents of ` receipts/data ` .
179
+ This line will ensure only the contents of ` pictures/cake ` is ignored, and
180
+ not the contents of ` pictures/pizza ` .
181
181
182
182
As with most programming issues, there
183
183
are a few alternative ways that one may ensure this ignore rule is followed.
@@ -231,13 +231,13 @@ Given a directory structure that looks similar to the earlier Nested Files
231
231
exercise, but with a slightly different directory structure:
232
232
233
233
``` bash
234
- receipts/data
235
- receipts/images
236
- receipts/plots
237
- receipts/analysis
234
+ pictures/cake
235
+ pictures/pizza
236
+ pictures/pie
237
+ pictures/brownie
238
238
```
239
239
240
- How would you ignore all of the contents in the receipts folder, but not ` receipts/data ` ?
240
+ How would you ignore all of the contents in the pictures folder, but not ` pictures/pie ` ?
241
241
242
242
Hint: think a bit about how you created an exception with the ` ! ` operator
243
243
before.
@@ -247,13 +247,13 @@ before.
247
247
## Solution
248
248
249
249
If you want to ignore the contents of
250
- ` receipts /` but not those of ` receipts/data /` , you can change your ` .gitignore ` to ignore
251
- the contents of receipts folder, but create an exception for the contents of the
252
- ` receipts/data ` subfolder. Your .gitignore would look like this:
250
+ ` pictures /` but not those of ` pictures/pie /` , you can change your ` .gitignore ` to ignore
251
+ the contents of pictures folder, but create an exception for the contents of the
252
+ ` pictures/pie ` subfolder. Your .gitignore would look like this:
253
253
254
254
``` output
255
- receipts /* # ignore everything in receipts folder
256
- !receipts/data / # do not ignore receipts /data/ contents
255
+ pictures /* # ignore everything in pictures folder
256
+ !pictures/pie / # do not ignore pictures /data/ contents
257
257
```
258
258
259
259
:::::::::::::::::::::::::
@@ -267,23 +267,23 @@ receipts/* # ignore everything in receipts folder
267
267
Assuming you have an empty .gitignore file, and given a directory structure that looks like:
268
268
269
269
``` bash
270
- receipts /data/market_position /gps/a.dat
271
- receipts /data/market_position /gps/b.dat
272
- receipts /data/market_position /gps/c.dat
273
- receipts /data/market_position /gps/info.txt
274
- receipts /plots
270
+ pictures /data/location /gps/a.dat
271
+ pictures /data/location /gps/b.dat
272
+ pictures /data/location /gps/c.dat
273
+ pictures /data/location /gps/info.txt
274
+ pictures /plots
275
275
```
276
276
277
277
What's the shortest ` .gitignore ` rule you could write to ignore all ` .dat `
278
- files in ` receipts /data/market_position /gps` ? Do not ignore the ` info.txt ` .
278
+ files in ` pictures /data/location /gps` ? Do not ignore the ` info.txt ` .
279
279
280
280
::::::::::::::: solution
281
281
282
282
## Solution
283
283
284
- Appending ` receipts /data/market_position /gps/*.dat` will match every file in ` receipts /data/market_position /gps`
284
+ Appending ` pictures /data/location /gps/*.dat` will match every file in ` pictures /data/location /gps`
285
285
that ends with ` .dat ` .
286
- The file ` receipts /data/market_position /gps/info.txt` will not be ignored.
286
+ The file ` pictures /data/location /gps/info.txt` will not be ignored.
287
287
288
288
289
289
0 commit comments