Search code examples
gitignore

Can't except file / directory in git-ignore


I added the path /Documents/ to .gitignore in a previous commit. Now in an actual commit I'd like to add a specific file to the repository without using git add --force [file]. My .gitignore now contains entries as follows:

/Documents/
!/Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings

There aren't any paths cross referencing /Documents/ in any way.

I'm not able to add the file with git add [file] while git responds with:

$ git add Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings
The following paths are ignored by one of your .gitignore files:
Documents/Visual Studio 2015/Settings/CurrentSettings.vssettings
Use -f if you really want to add them.

I'm sure I've had read the documentation precisely. But while it's not working I obviously missed something. To clarify my tries:

/Documents/*
!/Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings

Documents/
!Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings

Documents/*
!Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings

These configurations didn't work as well.


Solution

  • As @John C mentioned and linked to

    https://git-scm.com/docs/gitignore#_pattern_format

    there is no way around than adding the file to the index using

    git add --force Documents/Visual\ Studio\ 2015/Settings/CurrentSettings.vssettings