Keep ignored files out of git status

GitGitignore

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

As I found in this post, .gitignore only works for untracked files. If you added files to repository, you can:

git update-index --assume-unchanged <file>

or remove them from repository by

git rm --cached <file>

Edit

This article explains that too

Solution 2 - Git

I've had this issue come up as well, it's probably because you added your ignored directory/files to .gitignore after they were marked as "to be tracked" by GIT in an initial commit flow.

So you need to clear the git tracking cache like so:

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

A more detailed explanation can be read here: http://www.frontendjunkie.com/2014/12/stop-git-from-tracking-changes-to.html

The above command also removed the remnants of the folder/files from your remote GIT origin. So your GIT repos become clean.

Solution 3 - Git

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." 

Solution 4 - Git

This surely works,

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

Solution 5 - Git

I assume you want not to add tmp directory (Visual Studio Platform)

1- add lines below to your local .gitignore file

## ignore tmp
/tmp/
./tmp/

3- backup and delete tmp Folder locally. (Backup somewhere else. eg desktop?)

4- Commit Changes to Local than Sync to Remote (eg. github).

After these steps your tmp directory wont be uploaded again.

Solution 6 - Git

From man git-lsfiles:

-i, --ignored
Show ignored files in the output. Note that this also reverses any exclude list present.

Personally I tend to keep doxygen files in my source tree, so I simply added this to my .gitignore (which is in the topmost directory of my source tree):

docs/*

Hope that helps.

Solution 7 - Git

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

Solution 8 - Git

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.propertieswhere 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?

Solution 9 - Git

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

Solution 10 - Git

like this

git --ignored myfolder

And will show status only for myfolder

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionknutonView Question on Stackoverflow
Solution 1 - GitMBOView Answer on Stackoverflow
Solution 2 - GitnewbreedofgeekView Answer on Stackoverflow
Solution 3 - GitRamisView Answer on Stackoverflow
Solution 4 - GitUsmanView Answer on Stackoverflow
Solution 5 - GitZen Of KursatView Answer on Stackoverflow
Solution 6 - GitBastiBenView Answer on Stackoverflow
Solution 7 - Githarshul arView Answer on Stackoverflow
Solution 8 - GitFrancislainy CamposView Answer on Stackoverflow
Solution 9 - GitßãlãjîView Answer on Stackoverflow
Solution 10 - GitAlexView Answer on Stackoverflow