XK0-004 · Question #238
A Linux administrator needs to add some files in a directory to the Git repository but must exclude some local .tmp files that are occasionally created by the scripts. Which of the following is the…
The correct answer is C. echo .tmp >> .gitignore. Adding .tmp to .gitignore is the proper way to permanently exclude temporary files from Git tracking without deleting them or using invalid command syntax.
Question
A Linux administrator needs to add some files in a directory to the Git repository but must exclude some local .tmp files that are occasionally created by the scripts. Which of the following is the BEST way to accomplish this task?
Options
- Agit rm .tmp
- Bgit add -x .tmp *
- Cecho .tmp >> .gitignore
- Drm -rf .tmp
How the community answered
(30 responses)- A3% (1)
- B3% (1)
- C93% (28)
Why each option
Adding .tmp to .gitignore is the proper way to permanently exclude temporary files from Git tracking without deleting them or using invalid command syntax.
git rm removes a file from Git's index but does not configure Git to ignore future .tmp files, so they would be tracked again the next time git add is run.
git add does not support an -x exclusion flag - this is invalid syntax and would produce an error.
Appending .tmp to .gitignore instructs Git to ignore all files matching that pattern across the repository. The .gitignore file is the standard Git mechanism for excluding file patterns, and using >> appends the rule without overwriting existing entries, making the exclusion persistent and applicable to all contributors.
rm -rf permanently deletes files from the filesystem rather than configuring Git to exclude them, which is destructive and does not solve the tracking problem.
Concept tested: Git file exclusion with .gitignore patterns
Source: https://git-scm.com/docs/gitignore
Topics
Community Discussion
No community discussion yet for this question.