45

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
  • 31,404
  • 26
  • 119
  • 182

5 Answers5

74

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

output*.txt
Ry-
  • 218,210
  • 55
  • 464
  • 476
10

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

for all extensions

startingFileName*.*

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

starting*.mp*

Extra useful-case could be Ignore files that ending with specified string

  • *.logs
  • *.css.map
  • *.etc.etc
dipenparmar12
  • 3,042
  • 1
  • 29
  • 39
7

Just add the following to your gitignore:

output*.txt

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

Ry-
  • 218,210
  • 55
  • 464
  • 476
Vedaad Shakib
  • 739
  • 7
  • 20
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
  • 27
0

If you want to ignore all files that have same starting but different ending names, then you can use this patters (e.g. output.txt, output.old.test.txt, output.save, output.anypattern):

//.gitignore
output.*
ABDULLOKH MUKHAMMADJONOV
  • 4,249
  • 3
  • 22
  • 40