.gitignore is ignored by Git

前端 未结 30 1343
梦毁少年i
梦毁少年i 2020-11-22 02:51

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?

相关标签:
30条回答
  • 2020-11-22 03:39

    If it seems like Git isn't noticing the changes you made to your .gitignore file, you might want to check the following points:

    • There might be a global .gitignore file that might interfere with your local one
    • When you add something into a .gitignore file, try this:

      git add [uncommitted changes you want to keep] && git commit
      git rm -r --cached .
      git add .
      git commit -m "fixed untracked files"
      
    • If you remove something from a .gitignore file, and the above steps maybe don't work,if you found the above steps are not working, try this:

      git add -f [files you want to track again]
      git commit -m "Refresh removing files from .gitignore file."
      
      // For example, if you want the .java type file to be tracked again,
      // The command should be:
      //     git add -f *.java
      
    0 讨论(0)
  • 2020-11-22 03:40

    As with the other solutions, commit first and be aware that you will lose any un-committed changes.

    I had better results with this:

    git rm -r --cached .
    git reset HEAD --hard
    git status
    

    Note that the status shouldn't have any modified files now.

    0 讨论(0)
  • 2020-11-22 03:40

    I just ran into this issue. The content within my .gitignore file continued to appear in the list of untracked files.

    I was using this to create the ignore file:

    echo "node_modules" > .gitignore
    

    It turns out that the double quotations were causing the issue for me. I deleted the ignore file and then used the command again without quotes, and it worked as expected. I did not need to mess with the file encoding. I'm on a Windows 10 machine using Cmder.

    Example:

    echo node_modules > .gitignore
    
    0 讨论(0)
  • 2020-11-22 03:41

    For me none of the previous answers worked. I had to copy .gitignore text into the exclude.txt file found at

    <Your-project-folder>\.git\info
    

    Once done, refresh your changes and all the untracked files are gone. Commit as usual.

    0 讨论(0)
  • 2020-11-22 03:41

    I had this problem, with a .gitignore file containing this line:

    lib/ext/
    

    I just realized that in fact, this directory is a symbolic link to a folder somewhere else:

    ls -la lib/ext/
    lrwxr-xr-x 1 roipoussiere users 47 Feb  6 14:16 lib/ext -> /home/roipoussiere/real/path/to/the/lib
    

    On the line lib/ext/, Git actually looks for a folder, but a symbolic link is a file, so my lib folder is not ignored.

    I fixed this by replacing lib/ext/ by lib/ext in my .gitignore file.

    0 讨论(0)
  • 2020-11-22 03:42

    Just remove the folder or file, which was committed previously in Git, by the following command. Then gitignore file will reflect the correct files.

        git rm -r -f "folder or files insides"
    
    0 讨论(0)
提交回复
热议问题