简体   繁体   中英

How do I ignore files with a .gitignore file?

Always when I run git status some files are listed as untracked, that is how it should be. But I would like to not have them listed there everytime I run git status . As what I have understood, I should add those files to an .gitignore -file.

In my project I have a file .classpath and a directory .gradle/* that I want to ingore.

My .gitignore file looks like this:

.classpath
.gradle/*

but these files are still listed as "untracked" when I run git status . Is there anything wrong with my .gitignore file or how should I fix this?


Here is my git status output:

C:\myproject>git status
# On branch master
# 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/Test.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .classpath
#       .gitignore
#       .gradle/
no changes added to commit (use "git add" and/or "git commit -a")

I found out that the paths in my .gitignore file had a space in the end of each row. When I removed the space char from each line in .gitignore it worked fine. This is how I created my .gitignore file:

https://superuser.com/a/498909/27037

echo .classpath> .gitignore
echo .gradle/*>> .gitignore

and before I used this commands (does not work):

echo .classpath > .gitignore
echo .gradle/* >> .gitignore

This works for me:

.classpath
.gradle/

Make sure you git add . to stage the .gitignore file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM