0

The question

How do I generally .gitignore Log/log folders, but include my specific NetTerminal/Log/ folder and contents below it?


Background

We're using Azure DevOps and have a repository with the .gitignore template file "VisualStudio".

The .gitignore file has by default this line:

[Ll]og/

It happens that we have a Visual Studio project with a log class in: NetTerminal/Log/Log.cs. The folder and the file is being ignored by git because of the default line above. The NetTerminal folder is not below another Log folder, so that's not the reason.

I have tried adding any of the below, but they doesn't do anything, the file doesn't show up in Sourcetree's Uncommitted Changes list.

!NetTerminal/Log/
!NetTerminal/Log/*
!NetTerminal/Log/Log.cs

If I add a * to the default, as follows, now my custom file is found - but if I create a new Log folder somewhere else and add a file into it, it is also showing up, so the [Ll]og/* line is kind of ignored?

[Ll]og/*

Please advice? :-)

SvendK
  • 433
  • 3
  • 15
  • Ignore `[Ll]og/*` but force-add the file: `git add --force NetTerminal/Log/Log.cs` See https://stackoverflow.com/a/11126391/7976758 Found in https://stackoverflow.com/search?q=%5Bgitignore%5D+track+ignored+file – phd Apr 27 '22 at 11:31
  • @phd Will this automatically track any later changes or is it only my current change/adding of the file? – SvendK May 01 '22 at 14:11
  • To whoever duplicated my question (@phd?): My folder NetTerminal/Log/ is not located below another Log/ folder, which I already wrote in the question? Is the linked question still relevant here? I also noted that putting [Ll]og/* (asterisk) makes changes to any Log/ file not being ignored. Somwthing is rotten... :-) Please advice. – SvendK May 01 '22 at 14:18
  • "*Will this automatically track any later changes or is it only my current change/adding of the file?*" Only for added files. Untracked files are still ignored by `[Ll]og/` – phd May 01 '22 at 14:55
  • "*(To whoever duplicated my question (@phd?)*". Not me. The nickname is clearly written up in the box. – phd May 01 '22 at 14:55

0 Answers0