.gitignore is ignored by Git

前端 未结 30 1346
梦毁少年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:23

    I had this same problem. I believe the issue was a CR vs. CR+LF discrepancy. I stashed things in my .gitignore using CMD (on Windows 7) and the following command:

    Bad:

    echo "file_to_be_ignored.py" >> .gitignore
    echo "*~" >> .gitignore

    Etc.

    The issue was that this command does not place the correct end-of-line marker for Git to recognize the newlines (either CR or CR+LF when Git expects the other). I solved the problem by manually replacing each newline in Vim (Vim to the rescue!) and it worked perfectly.

    Try editing your .gitignore in Notepad++ or Vim (ideally). Even if the file looks like it's formatted correctly, try replacing the newlines. It sounds weird, I know, but it worked for me. :D

提交回复
热议问题