yesmeck
V2EX  ›  问与答

问个.gitignore的问题

  •  
  •   yesmeck · Jan 6, 2012 · 4869 views
    This topic created in 5249 days ago, the information mentioned may be changed or developed.
    我有这样一个git目录

    .
    |-- README
    `-- template
    ...`-- compiled
    ........|-- admin
    ........|...|-- haha
    ........|...`-- index.html
    ........|-- haha
    ........`-- index.html

    现在需要把template这个目录里除了两个index.html外都忽略掉

    master* $ cat .gitignore
    template/compiled/*
    !template/compiled/index.html
    !template/compiled/admin/index.html

    上面那样写的话template/compiled/admin/index.html这个文件还是会被忽略掉

    请教各位正确的写法
    7 replies    1970-01-01 08:00:00 +08:00
    yesmeck
        1
    yesmeck  
    OP
       Jan 6, 2012
    master* $ cat .gitignore
    template/compiled/*
    !template/compiled/admin/
    !template/compiled/index.html
    template/compiled/admin/*
    !template/compiled/admin/index.html

    发现这样写是可以,但是应该不用这么复杂吧。。。。
    coupgar
        2
    coupgar  
       Jan 6, 2012
    */index.html 试试
    yesmeck
        3
    yesmeck  
    OP
       Jan 6, 2012
    @coupgar
    template/compiled/*
    !template/*/index.html

    这样写admin下面的还是会被忽略掉
    9hills
        4
    9hills  
       Jan 6, 2012
    在template下新建.gitignore:
    /*¬
    !/.gitignore
    !/index.html
    !/admin

    然后再在admin目录下新建 .gitignore
    /*
    !/.gitignore
    !/index.html

    这种情形用子目录的.gitignore比全局要方便。
    9hills
        5
    9hills  
       Jan 6, 2012
    补充一下,上面的第一个/*后多了一个符号“¬”,请删掉。
    然后这种方法多用于git添加空目录。。只需要前两行
    /*
    !/.gitignore
    kaichen
        6
    kaichen  
    PRO
       Jan 6, 2012
    @yesmeck

    用*/index.html,然后用git add -f把需要的那两个加进来,这样不折腾。
    yesmeck
        7
    yesmeck  
    OP
       Jan 6, 2012
    @9hills

    OK,就这么做了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3095 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:13 · PVG 21:13 · LAX 06:13 · JFK 09:13
    ♥ Do have faith in what you're doing.