XK0-005 · Question #171
An administrator is reviewing updates in the master online Git repository and notices a file named . The file contains passwords and should only be in the administrator's local repository, not the…
The correct answer is D. echo ".htaccess" >> .gitignore. To prevent a specific file, like .htaccess, from being tracked and committed to a Git repository in the future, it must be added to the project's ignore list.
Question
An administrator is reviewing updates in the master online Git repository and notices a file named . The file contains passwords and should only be in the administrator's local repository, not the .htaccess online one. Which of the following would prevent this file from appearing online in the future?
Options
- Agit commit -m "File Update" -x .htaccess
- Bsed -i 's/#Preserve Hidden=True/Preserve Hidden=True/g' .git/config
- Cchown nobody:nodoby .htaccess
- Decho ".htaccess" >> .gitignore
How the community answered
(58 responses)- A3% (2)
- B7% (4)
- C10% (6)
- D79% (46)
Why each option
To prevent a specific file, like `.htaccess`, from being tracked and committed to a Git repository in the future, it must be added to the project's ignore list.
`git commit -x` is not a standard Git option for excluding files during a commit; `git commit` is used for recording changes.
`sed` is a stream editor for text, and modifying `.git/config` this way does not control which files Git ignores.
`chown` changes file ownership, which has no bearing on Git's tracking behavior.
Adding a file's name to the `.gitignore` file instructs Git to ignore that file, preventing it from being staged, committed, or pushed to the remote repository. The command `echo ".htaccess" >> .gitignore` appends the filename to this configuration file.
Concept tested: Git .gitignore functionality
Source: https://git-scm.com/docs/gitignore
Topics
Community Discussion
No community discussion yet for this question.