我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
我有文件夹应用程序/,我添加到.gitignore。在应用程序/文件夹中是文件夹application/language/gr。我如何包含这个文件夹?
我试过了
application/
!application/language/gr/
当前回答
关于这个问题还有很多类似的问题,所以我会把我之前写过的贴出来:
我让这个在我的机器上工作的唯一方法是这样做:
# Ignore all directories, and all sub-directories, and it's contents:
*/*
#Now ignore all files in the current directory
#(This fails to ignore files without a ".", for example
#'file.txt' works, but
#'file' doesn't):
*.*
#Only Include these specific directories and subdirectories:
!wordpress/
!wordpress/*/
!wordpress/*/wp-content/
!wordpress/*/wp-content/themes/
!wordpress/*/wp-content/themes/*
!wordpress/*/wp-content/themes/*/*
!wordpress/*/wp-content/themes/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*/*
请注意,您必须显式地允许您想要包含的每个级别的内容。所以如果我在主题下面有子目录5,我仍然需要拼写出来。
这是@Yarin的评论:https://stackoverflow.com/a/5250314/1696153
这些都是有用的话题:
负模式在。gitignore中是如何工作的? gitignore排除规则实际上是如何工作的?
我也试过
*
*/*
**/**
和* * / wp-content /主题/ * *
或/ wp-content /主题/ * * / *
这些对我也没用。大量的试验和错误!
其他回答
我想跟踪jquery生产js文件,这是有效的:
node_modules/*
!node_modules/jquery
node_modules/jquery/*
!node_modules/jquery/dist/*
我在这里发现了一个类似的情况,在laravel中默认情况下,.gitignore忽略所有使用asterix的内容,然后覆盖公共目录。 (这也是与主答案@Chris Johnsen相同的解决方案,只是可能更简洁一点。)
*
!public
!.gitignore
如果您遇到OP场景,这是不够的。
如果你想提交一个特定的public子文件夹,例如,在你的public/products目录中,你想包含一个子文件夹深度的文件,例如,包含public/products/a/b.jpg,它们不会被正确检测到,即使你像这样特别地添加它们!/public/products, !public/products/*等。
解决方案是确保像这样为每个路径级别添加一个条目来覆盖它们。
*
!.gitignore
!public/
!public/*/
!public/products/
!public/products/*
!public/products/*/
!public/products/*/
!public/products/*/*
添加一个额外的答案:
!/.vs/ <== include this folder to source control, folder only, nothing else
/.vs/* <== but ignore all files and sub-folder inside this folder
!/.vs/ProjectSettings.json <== but include this file to source control
!/.vs/config/ <== then include this folder to source control, folder only, nothing else
!/.vs/config/* <== then include all files inside the folder
结果如下:
这是另一个遍历目录结构以获得所需内容的示例。注意:我没有排除Library/,而是排除Library/**/*
# .gitignore file
Library/**/*
!Library/Application Support/
!Library/Application Support/Sublime Text 3/
!Library/Application Support/Sublime Text 3/Packages/
!Library/Application Support/Sublime Text 3/Packages/User/
!Library/Application Support/Sublime Text 3/Packages/User/*macro
!Library/Application Support/Sublime Text 3/Packages/User/*snippet
!Library/Application Support/Sublime Text 3/Packages/User/*settings
!Library/Application Support/Sublime Text 3/Packages/User/*keymap
!Library/Application Support/Sublime Text 3/Packages/User/*theme
!Library/Application Support/Sublime Text 3/Packages/User/**/
!Library/Application Support/Sublime Text 3/Packages/User/**/*macro
!Library/Application Support/Sublime Text 3/Packages/User/**/*snippet
!Library/Application Support/Sublime Text 3/Packages/User/**/*settings
!Library/Application Support/Sublime Text 3/Packages/User/**/*keymap
!Library/Application Support/Sublime Text 3/Packages/User/**/*theme
> git添加库
> git 状态
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap
new file: Library/Application Support/Sublime Text 3/Packages/User/ElixirSublime.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/Package Control.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/RESTer.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/SublimeLinter/Monokai (SL).tmTheme
new file: Library/Application Support/Sublime Text 3/Packages/User/TextPastryHistory.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/ZenTabs.sublime-settings
new file: Library/Application Support/Sublime Text 3/Packages/User/adrian-comment.sublime-macro
new file: Library/Application Support/Sublime Text 3/Packages/User/json-pretty-generate.sublime-snippet
new file: Library/Application Support/Sublime Text 3/Packages/User/raise-exception.sublime-snippet
new file: Library/Application Support/Sublime Text 3/Packages/User/trailing_spaces.sublime-settings
关于这个问题还有很多类似的问题,所以我会把我之前写过的贴出来:
我让这个在我的机器上工作的唯一方法是这样做:
# Ignore all directories, and all sub-directories, and it's contents:
*/*
#Now ignore all files in the current directory
#(This fails to ignore files without a ".", for example
#'file.txt' works, but
#'file' doesn't):
*.*
#Only Include these specific directories and subdirectories:
!wordpress/
!wordpress/*/
!wordpress/*/wp-content/
!wordpress/*/wp-content/themes/
!wordpress/*/wp-content/themes/*
!wordpress/*/wp-content/themes/*/*
!wordpress/*/wp-content/themes/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*
!wordpress/*/wp-content/themes/*/*/*/*/*
请注意,您必须显式地允许您想要包含的每个级别的内容。所以如果我在主题下面有子目录5,我仍然需要拼写出来。
这是@Yarin的评论:https://stackoverflow.com/a/5250314/1696153
这些都是有用的话题:
负模式在。gitignore中是如何工作的? gitignore排除规则实际上是如何工作的?
我也试过
*
*/*
**/**
和* * / wp-content /主题/ * *
或/ wp-content /主题/ * * / *
这些对我也没用。大量的试验和错误!