search

Home  >  Q&A  >  body text

Git wants to ignore a folder but not a file. The setting rules are invalid. What's going on?

If you want to ignore all file tracking in the upload folder, but not ignore index.html, single rule

Set as follows in the .gitignore file

uploads/*

uploads/!index.html

But it doesn’t work, index.html is also ignored and not tracked. Is there something wrong with this syntax?

Git version 2.6.3

天蓬老师天蓬老师2772 days ago617

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-05-02 09:42:59

    upload
    !upload/index.html

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:42:59

    Create a new .gitignore under the upload folder with the following content:

    *
    !.gitignore
    !index.html

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:42:59

    Floor 2 is correct, if you don’t want to upload文件夹下新增.gitignore, you can put your code

    uploads/*
    
    uploads/!index.html
    

    Swap the positions, because your rule is

    Filterupload文件夹下的所有文件, 然后你再不让其忽滤index.html, all files have been filtered, of course index.html no longer exists

    reply
    0
  • 某草草

    某草草2017-05-02 09:42:59

    My personal test was to write it like thisuploads/* uploads/!index.htmlIt didn’t work. Later I researched it and found that it can be written like this. See my blog post http://blog.csdn.net/CalShell...

    reply
    0
  • Cancelreply