1

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: !.gitgnore

  • And the init.vim in the same directory: !init.vim

  • Also don't ignore the folder bundle: !bundle

  • But 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...

LastSecondsToLive
  • 744
  • 10
  • 24

1 Answers1

2

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.vim then I switched my .gitignore back to:* !.gitinore !init.vim to ignore everything, but since bundle/vim-airline/autoload/airline/themes/kalisi.vim is already tracked, changes will get tracked in the future.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • When using this `.gitignore` I *again* get *bundle/* (together with *old.bundle/* as only untracked files. It seems like now the whole `bundle/` is included. Do you have any idea why? – LastSecondsToLive Nov 29 '15 at 14:05
  • @LastSecondsToLive you need to `git add bundle/vim-airline/autoload/airline/themes/kalisi.vim`, before a `git status` shows you what you want: if nothing is added yet, the status just stops at the first untracked folder. – VonC Nov 29 '15 at 14:07
  • Yeah, `git status` then shows `bundle/vim-airline/autoload/airline/themes/kalisi.vim` as staged, but now `bundle/neobundle.vim/`, `bundle/vim-airline/autoload/airline/init.vim` and `bundle/vim-airline/t/` (*subdirectories of `bundle`*) are shown as untracked and I wanted to ignore these. – LastSecondsToLive Nov 29 '15 at 14:11
  • @LastSecondsToLive so try and those folders content (after the last rule), as `*.vim/*`. – VonC Nov 29 '15 at 14:14
  • It was still not working (the other sub-directories still showed up). This is what I did: I created a commit with `bundle/vim-airline/autoload/airline/themes/kalisi.vim` then I switched my `.gitignore`back to:`* !.gitinore !init.vim` to ignore *everything*, but since `bundle/vim-airline/autoload/airline/themes/kalisi.vim` is already tracked, changes will get tracked in the future. – LastSecondsToLive Nov 29 '15 at 14:25
  • Thank you really much for your time. – LastSecondsToLive Nov 29 '15 at 14:26
  • @LastSecondsToLive That will work! I have included your approach in the answer for more visibility. – VonC Nov 29 '15 at 14:28