繁体   English   中英

gitignore不工作 - 想要忽略除gitignore文件以外的所有内容以保留“空”目录

[英]gitignore not working - want to ignore everything but gitignore file to keep an 'empty' directory

我在几个目录(例如log/ )中有一个.gitignore文件,其中包含以下内容:

*            " Ignore everything in this directory
!.gitignore  " Except this file

尽管如此,如果该目录中有一个文件, git status会向我显示它是新的但未跟踪。

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       log/blah.log
nothing added to commit but untracked files present (use "git add" to track)

我发现stackoverflow上的其他帖子建议在第一行和各种其他形式或随机伏都教上发表评论,但没有任何效果。

简单地说,我想在我的仓库中存在一个tmp/log/目录,但是空的。 我不希望任何人被骚扰将他们的日志和tmp文件添加到这些目录。

你期望双引号在你的.gitignore文件中表现得像一个评论吗? 你有这个......

*            " Ignore everything in this directory
!.gitignore  " Except this file

......但那就是你想要的。 如果你简单地替换它:

*
!.gitignore

它会工作得很好。 看:

$ ls -A
dir1 .git
$ ls -A dir1
.gitignore
$ cat dir1/.gitignore
*
!.gitignore
$ git status
# On branch master
nothing to commit (working directory clean)
$ touch dir1/file{1,2,3}
$ ls -A dir1
file1 file2 file3 .gitignore
$ git status
# On branch master
nothing to commit (working directory clean)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM