Keep ignored files out of git status

Viewed 101613

I would like to stop Git from showing ignored files in git status, because having tons of documentation and config files in the list of Changed but not updated files, renders the list half-useless.

Is it normal for Git to show these files?

I put the ignore information in a .gitignore file in the root directory of the Git repository and they are not added when using git add . but it seems that they are not fully ignored either, as they show up in the aforementioned list and do not show up in the list printed by git ls-files --others -i --exclude-standard. Only files matched by the patterns in ~/.gitignore show up there.

Could it be because at an earlier stage I didn't ignore them and they were thus committed at least once?

10 Answers

Problem can be that this file is still in the git cache. To solve this problem needs to reset git cache.

For single file

git rm --cached <file>

For whole project

Reset git cache. It is good command if you committed project when .gitignore file was not added.

git rm -r --cached . 

Commit changes

git add . 
git commit -m ".gitignore was fixed." 

This surely works,

git rm --cached -r [folder/file name]

Following steps work for untracked files only. This info is applicable for following configuration:

Platform: linux

Git version: git version 1.8.3.1

Put list of files to be ignored in "exclude" file present at following location.

<path till .git directory>/.git/info/exclude

Initial content of "exclude" file

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

Final content of "exclude" file

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~


*.tar
*.gch

As per the accepted answer, you can assume the file as unchanged, so that whatever you do on your local machine is not commited to your remote branch.

Something like git update-index --assume-unchanged src/main/resources/config.properties where src/main.resources/config.properties is a sample for the path to find that file within your project.

Now, if you want to remove the file completely from your repository, you may want to use remove cached instead as of `git rm --cached

This scenario could be applicable on the following situation:

Let's suppose I have a file where I store passwords. I've initially commited that file with wrong details, just so my colleagues have that same file on their machines. However, now I've added my correct details on my local machine. How do I prevent that file from being accidentally committed again with the now correct password details?

after Make changes in .gitignore file. follow these simple steps

git rm -r --cached .

Run git add .

git commit -m "Commit message"

To check

git status
Related