git - 让 .gitignore 不忽略顶级目录中的 .htaccess 文件

标签 git .htaccess commit

我试图忽略除 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/

相关文章:

.htaccess - 强制 HTTPS 到一个目录 - 删除 WWW

php - 是否可以重定向发布数据?

mercurial - 在 Mercurial 中对一组提交进行分组?

svn - 编辑提交注释时如何取消 svn 提交(命令行客户端)

git 扩展名来显式跟踪文件重命名?

git - 如何使用 git 维护网站的 2 个版本?

git clone 总是以 "Failed sending HTTP request"失败

git - git log --oneline --graph 输出的意义

php - 将 .htaccess 与 php5.4 内置服务器一起使用

java - Cassandra 2.1.3。如何提取CommitLog