0

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.

codekandis
  • 712
  • 1
  • 11
  • 22
  • 1
    I had luck in a similar setup (but Linux) when using your first try. Can you make sure that didn't work? One thing to note is "It is not possible to re-include a file if a parent directory of that file is excluded." - https://git-scm.com/docs/gitignore – John C Mar 03 '17 at 20:51
  • The first try should work properly as mentioned by the documentation. I'm pretty sure there is no problem with the Windows environment (especially while I'm using the recent GIT release). Reagarding to your note I'm referring to [gitignore directory exception not working](http://stackoverflow.com/questions/16678936/gitignore-directory-exception-not-working), but it doesn't solved my problem. – codekandis Mar 03 '17 at 21:18
  • I'm sorry. I missed the link in your comment. Explains everything. Thx. – codekandis Mar 04 '17 at 22:05

1 Answers1

0

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
codekandis
  • 712
  • 1
  • 11
  • 22