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?
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
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.
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]
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.
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.
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
like this
git --ignored myfolder
And will show status only for myfolder
Success story sharing
git status -- <file>
show "Changes not staged for commit" or "Untracked files" for your file? The former is if you already have file in index and I would need more informations to solve your problem (better create separate question with git messages shown and just post link to it in comment). The later is for files which are not tracked by git (yet), but are not in.gitignore
file and can be freely added to index.