I'm surprised that simple patterns like *.user in a .gitignore file seem to match files and folder names.
ringods$ mkdir TestIgnore ringods$ cd TestIgnore/ ringods$ git init Initialized empty Git repository in /Users/ringods/Projects/hostbasket/TestIgnore/.git/ ringods$ git status # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track) ringods$ mkdir security.user ringods$ touch security.user/file_may_not_be_ignored.txt ringods$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # security.user/ nothing added to commit but untracked files present (use "git add" to track) ringods$ echo "*.user"> .gitignore ringods$ cat .gitignore *.user ringods$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .gitignore nothing added to commit but untracked files present (use "git add" to track)
Do I have the wrong expectation? How can I write a simple ignore files with extension blah and prevent folders ending in .blah being matched?
The gitignore man page mentions that patterns without a / are matched using shell glob pattern functionality, but it doesn't really tell me if it matches files only or files and directories.
. gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
An asterisk " * " matches anything except a slash. The character " ? " matches any one character except " / ". The range notation, e.g. [a-zA-Z] , can be used to match one of the characters in a range.
gitignore file is a text file that tells Git which files or folders to ignore in a project. A local . gitignore file is usually placed in the root directory of a project. You can also create a global . gitignore file and any entries in that file will be ignored in all of your Git repositories.
.gitignore
patterns just match directory entries or paths. There's no specific way to say "only match a regular file", however if you supply a trailing /
then the pattern will only match a directory. You can use this to match non-directories (which is almost what you want) with two patterns:
*.user # ignore all paths ending in '.user' !*.user/ # but don't ignore these paths if they are directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With