.gitignore is not working

My .gitignore file seems to be being ignored by git - could the .gitignore file be corrupt? Which file format, locale or culture does git expect?

My .gitignore :

#this is a comment
debug.log
nbproject/

Output from git status :

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

I would like debug.log and nbproject/ not to appear in the untracked files list.

Where should I start looking to fix this?


Even if you haven't tracked the files so far, git seems to be able to "know" about them even after you add them to .gitignore .

NOTE : First commit your current changes, or you will lose them.

Then run the following commands from the top folder of your git repo:

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

When .gitignore file is not working (adding something into .gitignore file or removing something from .gitignore file), you can check the following tips:

  • you must pay attention to the global gitignore file which sometimes may influence your gitignore.
  • When you add something into .gitignore file, as the person who answered this question first:

    git rm -r --cached .
    git add .
    git commit -m "fixed untracked files"  
    
  • When you remove something from .gitignore file. The above steps will not work for you . You can try this:
  •     git add -f "filetype"
        git commit -m "Refresh removing filetype from .gitignore file."
    

    the "filetype" means the file or filetype you want to remove from the .gitignore file. You want to make the filetype be tracked again.


    Fixed. Ok, I created the .gitignore file in notepad on windows and it wasn't working. When I viewed the .gitignore file in linux it looked like organised gibberish - perhaps notepad had written out unicode rather than ascii or whatever 8-bit is.

    So I rewrote the file on my linux box, and when I pulled it back into windows it works fine! Hurrah!

    链接地址: http://www.djcxy.com/p/4008.html

    上一篇: 我怎样才能撤销git reset

    下一篇: .gitignore不起作用