nerdexam
CompTIA

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.

Security

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)
  • A
    3% (2)
  • B
    7% (4)
  • C
    10% (6)
  • D
    79% (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.

Agit commit -m "File Update" -x .htaccess

`git commit -x` is not a standard Git option for excluding files during a commit; `git commit` is used for recording changes.

Bsed -i 's/#Preserve Hidden=True/Preserve Hidden=True/g' .git/config

`sed` is a stream editor for text, and modifying `.git/config` this way does not control which files Git ignores.

Cchown nobody:nodoby .htaccess

`chown` changes file ownership, which has no bearing on Git's tracking behavior.

Decho ".htaccess" >> .gitignoreCorrect

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

#Git#.gitignore#Version Control#Security Best Practices

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice