简体   繁体   English

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

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

I have a .gitignore file in a few directories (ex. log/ ) with the following contents: 我在几个目录(例如log/ )中有一个.gitignore文件,其中包含以下内容:

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

Nonetheless, if there is a file in that directory, git status shows it to me saying it's new but untracked. 尽管如此,如果该目录中有一个文件, 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)

I have found other posts on stackoverflow suggesting putting a comment on the first line and various other forms or random voodoo, but nothing has worked. 我发现stackoverflow上的其他帖子建议在第一行和各种其他形式或随机伏都教上发表评论,但没有任何效果。

Simply, I want a tmp/ and log/ directory to exist in my repo, but empty. 简单地说,我想在我的仓库中存在一个tmp/log/目录,但是空的。 I don't want anyone to be harassed to add their log and tmp files to these directories. 我不希望任何人被骚扰将他们的日志和tmp文件添加到这些目录。

Are you expecting the double-quote to act like a comment in your .gitignore file? 你期望双引号在你的.gitignore文件中表现得像一个评论吗? You've got this... 你有这个......

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

...but that's doing what you want. ......但那就是你想要的。 If you replace it with simply: 如果你简单地替换它:

*
!.gitignore

It will work just fine. 它会工作得很好。 Watch: 看:

$ 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