CompTIACompTIA
XK0-005 · Question #1233
XK0-005 Question #1233: Real Exam Question with Answer & Explanation
The correct answer is C: echo .tmp >> .gitignore. To prevent Git from tracking specific local files like temporary files, add their patterns to the .gitignore file.
Scripting, Containers, and Automation
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
Explanation
To prevent Git from tracking specific local files like temporary files, add their patterns to the .gitignore file.
Common mistakes.
- A.
git rm .tmpwould remove the file.tmpfrom the Git repository if it was already tracked, but it does not prevent future untracked.tmpfiles from being listed by Git. - B.
git add -x .tmp *uses an invalid flag-xforgit add;git addis used to stage files for commit, not to exclude them. - D.
rm -rf .tmpdeletes the.tmpfile from the filesystem but does not configure Git to ignore similar files in the future.
Concept tested. Git file exclusion (.gitignore)
Reference. https://git-scm.com/docs/gitignore
Topics
#Git#Version Control#.gitignore#File Exclusion
Community Discussion
No community discussion yet for this question.