1

I want to ignore all files with the pattern d*.cpp. These file could be in the same directory as .gitignore, or in any sub-directory.

How should that rule look like? **/d*.cpp does not do what I think it should.

belln
  • 258
  • 3
  • 10
  • 2
    Are you sure you haven't added or committed some of the files previously? – choroba Mar 22 '17 at 09:38
  • `git status` lists for example `src/mod/dd_file.cpp` as Untracked file (with the rule in place), so it should not be previously committed. – belln Mar 22 '17 at 09:58

2 Answers2

4

The pattern looks correct. git will ignore any d*.cpp file anywhere in your git repository. However; gitignore works only for untracked files; as written in the documentation:

gitignore - Specifies intentionally untracked files to ignore

If you want to ignore changes to the d*.cpp files that have already been added to your repository; you can use --skip-worktree or --assume-unchanged. You can take a look at this answer for a good explanation of these two concepts. (special thanks to @1615903 for pointing me to skip-worktree)

Community
  • 1
  • 1
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • 2
    `--skip-worktree` is more appropriate, see here: https://stackoverflow.com/a/13631525/1615903 – 1615903 Mar 22 '17 at 09:59
1

The ** syntax is not available for .gitignore in early versions of git. The solution is to upgrade to 1.8.2.1 or later.

belln
  • 258
  • 3
  • 10