CS FundamentalsVery hardProduct-company placement · Git interview

A .gitignore contains the two lines logs/ and !logs/keep.log. A developer expects logs/keep.log to be tracked, but git status never shows it. Why?

  1. A. Negation patterns are not supported in .gitignore
  2. B. The negation must come before the directory pattern
  3. C. Git cannot re-include a file whose parent directory is excluded; using logs/* instead of logs/ fixes it
  4. D. keep.log must be committed with git add -f once, after which the negation takes effect

Correct answer: C. Git cannot re-include a file whose parent directory is excluded; using logs/* instead of logs/ fixes it

logs/ excludes the directory itself, so git never looks inside it and the negation has nothing to act on. logs/* ignores the contents instead, letting !logs/keep.log re-include that one file.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic