Git: inverse ignoring (.gitignore)

前端 未结 3 501
孤独总比滥情好
孤独总比滥情好 2020-12-09 03:24

I created a repository for my home folder. This is my .gitignore file:

!.vim/plugin/*
!.vim/doc/*
.*
*
.viminfo
.vim/.netrwhist
.vim-fuf-data/fi         


        
相关标签:
3条回答
  • 2020-12-09 04:11

    Try moving the negated lines (those starting with !) to the bottom of the .gitignore file.

    See the Examples section here

    0 讨论(0)
  • 2020-12-09 04:16

    Another way would be to ignore only top level files and directories, and in the whitelisted directories do the same if necessary, as in this answer to a related question

    For example my .gitignore now looks like this

    /*
    !.gitignore
    !.vimrc
    !.bashrc
    !.vim/
    .vim/.netrwhist
    !.gconf/
    .gconf/apps/*
    !.gconf/apps/gnome-terminal
    !bin/
    

    The answer of Deve makes git very slow because it searches all directories under your homedir. (In the specific case of using git for the settings in your homedir)

    0 讨论(0)
  • In line 4 you're ignoring everything with *. This overrides the previous negating pattern. From the man page:

    within one level of precedence, the last matching pattern decides the outcome

    Where "level of precedence" means different sources for ignore patterns like .gitignore and $GIT_DIR/info/exclude.

    If you want to ignore everything but the patterns beginning with ! you should move the * to the beginning of .gitignore


    Edit

    I found a solution with the help of another question on SO:

    *
    !*/
    !.vim/plugin/*
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题