Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode 6 - Ignoring Things: Exercise Ignoring Nested Files #634

kekoziar opened this issue May 7, 2019 · 0 comments


None yet
1 participant
Copy link

commented May 7, 2019

The exercise prompt is

Given a directory structure that looks like:


How would you ignore only "results/plots" and not "results/data"?

The construction of a .gitignore file that ignores one subdirectory has two solutions. One is trivial; the other is complex and, imo, requires intermediate to advanced knowledge of how git travels along directory paths.

The first and easiest solution is to specify directly all directories to ignore. e.g.
change results/ to results/plots in the .gitignore file.

The second answer refers to the exclamation point operator, which has not yet been introduced. This answer allows git to ignore everything in a folder except one subfolder. The .gitignore file requires alternating statements between ignoring and unignoring more granular levels of the directory until the end directory that you don't want ignored is reached.

For this example, assume results/data/ contains two files, data.dat and data.txt. You want to ignore everything in the results directory except results/data/. The following sequence will allow results/data to be accessed, while ignoring all other .dat files and all other files and subdirectories within /results/.


If the asterisk at the end of the second line, results/*, is not included, everything in the directory will be ignored.

It is similarly important to include both the third and fourth lines. The third line tells git it's okay to look at the directory results/data/, while the fourth line includes all files in the directory (overriding the previous exclusion of *.dat files. Oddly enough, git doesn't care what order the third and fourth lines are in.

I have now tested this on MacOS and GitBash with the same results.

That said, I'm not sure if this exercise is appropriate for the lesson because of the intermediate/advanced solution. Perhaps the second solution should be listed as intermediate/advanced content, and a later exercise introduced, "Ignoring Nested Files, Part 2", with the explicit explanation and solution. But, IMO, the answer is confusing and somewhat incorrect because it refers to a solution to a different exercise that over simplifies the exclamation point operator, and doesn't address how it works with directories.

@kekoziar kekoziar added this to the June 2019 Release milestone May 7, 2019

@kekoziar kekoziar referenced this issue May 7, 2019


June 2019 Lesson Release checklist #611

7 of 12 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.