Git:忽略除目录之外的所有内容
我已阅读本手册: http://git-scm.com/docs/gitignore
当我使用 gitosis 时,我宁愿使用 .gitignore 而不是显式 git 命令。 手册上是这么说的:
当然,不使用 git 跟踪文件 只是不调用 git 的问题 添加它们。但很快就变成了 有这些未跟踪的文件很烦人 躺着;例如他们让 git add 。 实际上没用,他们保留 显示在 git 的输出中 状态。
你可以告诉 git 忽略某些 文件通过创建一个名为 .gitignore 在你的顶层 工作目录
我基本上想递归地忽略除两个目录之外的所有内容。假设 /mywebapp (包含两个子目录,如样式表和 javascripts)和 /mydata 是这两个目录。现在,我已经被告知 git 不跟踪目录,而只跟踪文件。 !-标记排除,所以我认为这也可以用于目录。我发现使用 * 会忽略其他一切。我将如何编写我的 .gitignore 文件?
我的问题不是如何通过显式添加来手动添加这些目录。我的问题是如何在 gitignore 文件中完成此操作。
感谢您的帮助、评论和反馈。
I have read this manual:
http://git-scm.com/docs/gitignore
As I am working with gitosis, I rather use a .gitignore than explicit git commands.
Thus says the manual:
Of course, not tracking files with git
is just a matter of not calling git
add on them. But it quickly becomes
annoying to have these untracked files
lying around; e.g. they make git add .
practically useless, and they keep
showing up in the output of git
status.You can tell git to ignore certain
files by creating a file called
.gitignore in the top level of your
working directory
I basically want to ignore everything, except two directories, recursively. Let's say /mywebapp (that contains two subdirectories like stylesheets and javascripts) and /mydata are those two directories. Now, I've been already told git does not track directories, but just files. The !-mark excludes, so I assume this could work with directories too. I figured out that using * would ignore everything else. How would I write up my .gitignore file?
My question is not how to add these directories manually by explicit adding. My question is how this is done inside a gitignore file.
Thanks for your help, comments and feedback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,“
*
”被委托给fnmatch
函数 并不总是在所有平台上都以相同的方式工作。使用我的 msysgit,我设法忽略所有子目录 content 除了一个
在您的情况下因此:
使用 '
*
' (而不是 '*/
') 在这种情况下有点太多了:它会忽略所有文件和目录......First, the '
*
' is delegated to thefnmatch
function which doesn't always works the same on all platform.With my msysgit, I manage to ignore all subdirectories content except one with
So in your case:
To use '
*
' (instead of '*/
') is a bit too much in this instance: it would ignore all files and directories...