I have the following folder structure:
/foo/ /foo/test.txt /foo/.gitkeep /foo/bar/test.txt /foo/bar/.gitkeep /foo/bar/baz/test.txt /foo/bar/baz/.gitkeep
Now I want to exclude all the files in the "foo" folder and all the files in my subfolders (and subfolders), with the exception of all .gitkeeps (to keep the folder structure). This should also work for more than three levels of subfolders.
The following gitignore rules work:
/foo/** !/foo/**/ !/foo/**/.gitkeep
Can someone explain why this works? Is there a cleaner way to do this?
The rule is simple:
Cannot re-include the file if the parent directory of this file is excluded.
That's why you need
ignore files and folders recursively:
/foo/**
( /foo/, , <! ' , foo/ : Git )
/foo/
!
foo/
:
!/foo/**/
, .gitkeep
.gitkeep
!/foo/**/.gitkeep
, .gitkeep .
( ):
/foo/** !**/.gitkeep
/**, .
/**
git check-ignore -v -- /path/to/.gitkeep
scm .gitignore:
.gitignore
*
**
!.gitkeep
"recursively" - , , : (, . /foo/), - .( ) (* **) gitignore ( !*), ( ) .
recursively
.
!*
. , .gitignore .
, , .
foo/, foo/bar/ foo/bar/baz/, .gitkeep.
foo/bar/
foo/bar/baz/
.gitignore :
* !*/ !.gitignore !.gitkeep
[: ]
* !*/ !.git*
, .
, .gitignore, - , .gitignore , , , , .
, .gitignore , . , , .gitignore. , .gitignore .
Source: https://habr.com/ru/post/1685958/More articles:flto with gcc7.2 - c ++Android Architecture Components ViewModel Context - androidHow to create CEF1 for Visual Studio 2017 - c ++How to output rows from an SQL table as extended on a daily basis using start and end dates? - dateProlog, how do I make a list of lists into one list? - prologSamsung device allocates memory for reverse navigation - androidcopy_to_user undefined on Linux kernel version 4.12.8 - linuxCreate a mask only in the first positions - arraysGitLab Docker Crash Error - Access Denied - gitlabErrors when publishing to an Angular 4 project in Visual Studio Team Services - angularAll Articles