简体   繁体   中英

How to git ignore everything but one folder?

I have a git repo in my home folder. I'm trying to NOT include basically the entirety of my home folder, with the exception of my .vim folder.

In my .gitignore, I have

* !.vim

The problem is that this only adds the .vim directory into my git repo, but not its files and its subdirectories (and its files, and its subdirectories, and so on). I'd like to have .vim and ALL of its subfiles and subdirectories into my git repo. How do I change this .gitignore for the desired behavior?

If you want to exclude a folder content , you would need to exclude first folders (because of the parent directory rule ):

*
!*/

Then you can exclude the .vim/ folder content:

!.vim/**

* includes the current directory, so you're being bitten by this:

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

I don't know of any way to say " everything in the top level directory except the top level directory ".

If you only want to put .vim into Git, you should put your Git repository in .vim .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM