问题
I'm trying to manage my neovim's init.vim with git.
I want to ignore everything except the init.vim in the same folder as the .gitignoreand one kalisi.vim in the directory
/bundle/vim-airline/autoload/airline/themes/
This is my current .gitignore:
# Ignore everything
*
# Exceptions
!.gitinore
!init.vim
!bundle
bundle/*
!bundle/vim-airline
bundle/vim-airline/*
!bundle/vim-airline/autoload
bundle/vim-airline/autoload/*
!bundle/vim-airline/autoload/airline
bundle/vim-airline/autoload/airline/*
!bundle/vim-airline/autoload/airline/themes
bundle/vim-airline/autoload/airline/themes/*
!bundle/vim-airline/autoload/airline/themes/kalisi.vim
My thoughts about this:
Ignore everything:
*Except this
.gitignore:!.gitgnoreAnd the
init.vimin the same directory:!init.vimAlso don't ignore the folder
bundle:!bundleBut everything in it:
bundle/*Except the folder
vim-airline:!vim-airline
I think you get the idea...
But if I execute git status now only get bundle/ as untracked file. Should't I get kalisi.vim or bundle/vim-airline/autoload/airline/themes/kalisi.vim?
I'm hoping for a more elegant way to be honest. I also heard about placing multiple .gitignore's in the directories, but the subdirectories are all projects with it's own .gitignore and this would create a huge amount of work to only not-ignore the right .gitignore.
I hope someone has an idea what to do, currently it just seems like the bundle/ directory is tracked, but not the content I want...
回答1:
As I mentioned in "How do I add files without dots in them (all extension-less files) to the gitignore file?", there is one rule to remember with .gitignore:
It is not possible to re-include a file if a parent directory of that file is excluded. (†)
(†: unless certain conditions are met in git 2.7+)
That means, when you exclude everything ('*'), you have to white-list folders ('/**/'), before being able to white-list files.
# Ignore everything
*
# Exceptions
!.gitinore
!init.vim
!/**/
!bundle/vim-airline/autoload/airline/themes/kalisi.vim
The OP LastSecondsToLive actually took a simpler approach:
I created a commit with
bundle/vim-airline/autoload/airline/themes/kalisi.vimthen I switched my.gitignoreback to:* !.gitinore !init.vimto ignore everything, but sincebundle/vim-airline/autoload/airline/themes/kalisi.vimis already tracked, changes will get tracked in the future.
来源:https://stackoverflow.com/questions/33983210/git-gitignore-in-subdirectories