我试图忽略除 www 目录中的 .htaccess 文件之外的所有文件。
我有这个:
# Ignore everything in this directory
*
# Except this file
!.gitignore
!/www/.htaccess
我也试过这个:
# Ignore everything in this directory
*
# Except this file
!.gitignore
!www/.htaccess
当我运行 git status
时,我没有看到 .htaccess 是一个添加的文件。我尝试提交 .gitignore 文件。依然没有。我遗漏了一些明显的东西,不是吗?
更新
我也试过这些:
# Ignore everything in this directory
*
*/\.htaccess
# Except these files
!.gitignore
!www/\.htaccess
和
# Ignore everything in this directory
*
*/.htaccess
# Except these files
!.gitignore
!www/.htaccess
最佳答案
我在我的机器上尝试了一些示例步骤,尝试它们并检查它们是否适合您。
cd ~/Desktop/test
mkdir www && touch .gitignore www/.gitkeep www/.htaccess www/file1 www/file2
git init && git add www/.gitkeep && git commit -m "gitkeep to make www trackable"
现在执行 git status
会显示给你
.gitignore
www/.htaccess
www/file1
www/file2
现在,在您的 .gitignore 文件中,添加以下两个条目
www/*
!www/.htaccess
现在执行 git status
显示
.gitignore
www/.htaccess
您现在可以使用 git add .
添加这两个文件并提交它们。
此外,一旦您确信上述命令有效,您可以删除我在示例中生成的 www/.gitkeep
(添加它是为了保持 www
可跟踪, git 不对文件夹进行版本控制)并添加 www/.htaccess
以减少冗余文件的开销。
关于git - 让 .gitignore 不忽略顶级目录中的 .htaccess 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19457301/