38

I have a program that generates text files output1.txt, output2.txt, output3.txt, etc.. I want Git to ignore these files. I can't block text files, as I have some text files that shouldn't be ignored. Also, the files are dynamically generated (there is no limit to the number appearing after “output”), so can't add the file names statically. Can someone please help me with this?

PS. I've checked out this Make .gitignore ignore everything except a few files, but it refers to a set of files alread known. In my case it might be a long list.

dreftymac
  • 29,742
  • 25
  • 114
  • 177

4 Answers4

59

Pattern matching doesn’t just work before the extension. Just as much as you can ignore *.txt, you can ignore:

output*.txt
Ry-
  • 209,133
  • 54
  • 439
  • 449
7

Just add the following to your gitignore:

output*.txt

* is a "wildcard", so it will match anything.

Ry-
  • 209,133
  • 54
  • 439
  • 449
Vedaad Shakib
  • 720
  • 7
  • 20
4

if you want to ignore files with starting letters, also you can do with extensions as well

for all extensions

startingFileName*.*

  1. files, extensions start with mp letters like mp3,mp4 etc

    starting*.mp*

dipenparmar12
  • 2,318
  • 1
  • 25
  • 34
3

Using * just as in regex matching (or wildcard matching) will do the job. Just provide the entry

output*.txt
into your .gitignore file, and the problem is solved!
T90
  • 567
  • 6
  • 26