V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yesmeck
V2EX  ›  问与答

问个.gitignore的问题

  •  
  •   yesmeck · 2012-01-06 15:41:06 +08:00 · 4306 次点击
    这是一个创建于 4509 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我有这样一个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 条回复    1970-01-01 08:00:00 +08:00
    yesmeck
        1
    yesmeck  
    OP
       2012-01-06 15:44:47 +08:00
    master* $ cat .gitignore
    template/compiled/*
    !template/compiled/admin/
    !template/compiled/index.html
    template/compiled/admin/*
    !template/compiled/admin/index.html

    发现这样写是可以,但是应该不用这么复杂吧。。。。
    coupgar
        2
    coupgar  
       2012-01-06 15:44:50 +08:00
    */index.html 试试
    yesmeck
        3
    yesmeck  
    OP
       2012-01-06 15:47:00 +08:00
    @coupgar
    template/compiled/*
    !template/*/index.html

    这样写admin下面的还是会被忽略掉
    9hills
        4
    9hills  
       2012-01-06 16:44:08 +08:00
    在template下新建.gitignore:
    /*¬
    !/.gitignore
    !/index.html
    !/admin

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

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

    用*/index.html,然后用git add -f把需要的那两个加进来,这样不折腾。
    yesmeck
        7
    yesmeck  
    OP
       2012-01-06 17:08:46 +08:00
    @9hills

    OK,就这么做了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2827 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:19 · PVG 11:19 · LAX 20:19 · JFK 23:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.