Reputation: 19175
Yes, this looks like a duplicate as I can see this has been asked a few times before. But none of the other answers I saw helped me.
I've got an Umbraco installation that I want to store in Git (GitHub to be exact) and I obviously want to omit log files and temp files that Umbraco creates.
I've got the following in my .gitignore file:
App_Data/TEMP/
App_Data/Logs/
App_Data/ClientDependency/
App_Data/Preview/
However, it does not work. Files in those directories still get added.
I've tried putting an asterisk on the end (docs say it shouldn't be needed - and it only deals with files in that directory if it is there.)
I've ensured there are no spaces at the end of each line.
I've double checked the capitalisation of the directory names.
I've swapped around the slashes from one way to the other.
If I put in the full path from the root of the repository it does work, but that's too specific. (Although I'm going to use that as a work around for the moment). I'd like to be able to reuse the .gitignore file easily if we create new Umbraco based projects.
Other rules that don't put in the full path (e.g. NuGet's packages folder) are being correctly processed.
packages/
That rule works - And I don't really see the difference.
Can anyone see what I'm doing wrong here?
UPDATE
The full path that works is this:
/src/Company.Client.Web/App_Data/Logs/
/src/Company.Client.Web/App_Data/TEMP/
/src/Company.Client.Web/App_Data/ClientDependency/
/src/Company.Client.Web/App_Data/Preview/
(I've obfuscated a bit of it, but that's what is there now)
Here's what GitHub for Windows is showing:
Update 2
The .git folder is at the root of the repository, so /
. In other words D:\github\RepositoryName\.git\
, for comparison the src
folder is D:\github\RepositoryName\src\
Upvotes: 0
Views: 2493
Reputation: 3181
Since since git 1.8.2 (March, 8th 2013), you can now use **
:
The patterns in
.gitignore
and.gitattributes
files can have**/
, as a pattern that matches 0 or more levels of subdirectory.E.g. "
foo/**/bar
" matches "bar
" in "foo
" itself or in a subdirectory of "foo
".
So you want:
**/App_Data/TEMP/
**/App_Data/Logs/
**/App_Data/ClientDependency/
**/App_Data/Preview/
Upvotes: 6
Reputation: 174329
When you specify a filename or a folder in .gitignore, it is ignored, no matter where it appears in your directory structure. That's why packages/
works.
The same is not true for partial paths like App_Data/TEMP/
.
What you can do is the following:
*/*/App_Data/TEMP/
This will ignore App_Data/TEMP
no matter how the two parent directories are named. But it will only work for those folders at this exact depth of the hierarchy, i.e. it will ignore these:
But it will not ignore these:
This is by design as stated in the documentation:
[When the pattern contains a slash but doesn't end with one], git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
Upvotes: 5
Reputation: 444
It seems that's a simple error. I guess you had set up your .gitignore file after putting your log files into your repo.
But actually, the .gitignore file is used to avoid some untracked files, but once a file had been added to any commit just once, it just passes the .gitignore check.
If you want to apply this .gitignore check, try git rm yourfiles , git commit -m "Your commit name" and then they'll never be tracked anymore. make sure you have a copy of them before trying this.
Upvotes: 0