user2456977 user2456977 -3 years ago 146
Javascript Question

Remove untracked file from appearing in git status

When I do

git status
this appears:

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: src/app.js
modified: src/view/view.js
modified: src/view/layout.js
modified: src/view/layout2.js
modified: src/view/layout3.js
modified: src/view/layout4.js
modified: src/view/layout5.js

Untracked files:
(use "git add <file>..." to include in what will be committed)


Usually I do
git add -A
to stage all changes at once but this would also add the untracked file. So now I need to painstakingly stage my changes one file at a time.

How do I stop the untracked file from appearing in
git status
? I do not want to delete the file, just ignore it, or have
git status
ignore it.

I tried doing things like:

git update-index --assume-unchanged hidemeplease.json

but to no avail.

Any ideas?

Answer Source

An untracked file, in Git, is a file whose path name does not appear in the index.

Since it's not in the index, you cannot tell git update-index to mark the index entry as "assume unchanged" or "skip worktree". But this is actually good news.

If a file is not in the index, git status will normally complain about it, and git add . would add it. To prevent these from occurring, list the file's path name in a .gitignore file.

The .gitignore file contains a list of path names that Git will shut up about, and not auto-add. So it should really be called .git-shut-up-about-these-files-and-do-not-auto-add-them. That name is kind of unweildy, though, hence .gitignore.

Note that if a file's path name is in the index, listing that file in a .gitignore file has no effect at all. That's why the current complaint is good news.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download