Home > front end >  Git ignore a folder except a given file outside the folder
Git ignore a folder except a given file outside the folder

Time:11-14

I had the following simple .gitignore file.

#  Local .terraform directories. Here .terraform is a folder
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# .tfvars files
*.tfvars

# .tfplan files
*.tfplan

# .pem files
*.pem

# .hcl files from Terraform v0.14 and newer
*.hcl

# working directory for web app
/globo_web_app/*

**/next-step.txt

Note that this makes git to ignore .terraform.lock.hcl file as well.

Also note that .terraform.lock.hcl is not inside of .terraform folder. See the shot below.

But Now I learnt that this .terraform.lock.hcl file gitignore file

I tried adding !.terraform.lock.hcl as shown be in the above screen shot. But it does not seem to work. Any ideas?

CodePudding user response:

Notice you still have this line in your .gitignore:

*.hcl

which, as you know, ignores all .hcl files. If you've added the !.terraform.lock.hcl before that line, it will not work. You need to change it to:

*.hcl
!.terraform.lock.hcl
  •  Tags:  
  • git
  • Related