I have two files I wish to ignore:
- .idea/workspace.xml
- someapp/src/.idea/workspace.xml
I thought adding this single rule to .gitignore will suffice:
.idea/workspace.xml
But it only catches the top-level .idea/workspace.xml (git status shows someapp/src/.idea/workspace.xml as untracked).
I also tried **/.idea/workspace.xml
, but this doesn't work at all. Help?
According to the gitignore man page:
(emphasis mine)
try this
/**/.idea/workspace.xml
As soon as the path contains a slash, Git will no longer check for a match in the path but instead will use the glob behaviour directly. As such, you cannot match for
.idea/workspace.xml
but only forworkspace.xml
.Git manual: gitignore.
This has changed in git 1.8.4
**/.idea/workspace.xml
should work now in this example.See the examples in gitignore manual:
So
.idea/workspace.xml
will match the root one but notsomeapp/src/.idea/workspace.xml
But depending on your fnmatch implementation, this is what you need in your .gitignore: