Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Git ignore a folder except a given file outside the folder

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But Now I learnt that this .terraform.lock.hcl file must be checked into VC. So it should not be ignored by git.

I am not able to achieve that.

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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading