Git 不会忽略跟踪的文件
Git 不会忽略对已提交文件的更改。
Git忽略的目的是什么
Git 忽略,忽略存储库中的噪音,例如:
$ git init
$ mkdir tmp
$ touch tmp/file1
$ touch tmp/file2
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# tmp/
nothing added to commit but untracked files present (use "git add" to track)
如果 .gitignore 文件被修改为忽略 tmp 目录:
$ echo "tmp" > .gitignore
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
tmp 目录内容不再列出 - 但 .gitignore 文件已列出(因为我刚刚创建了它并且文件本身没有被忽略)。
承诺,没有列出任何更改:
$ git add .gitignore
$ git commit -v -m "addding git ignore file"
[master (root-commit) d7af571] addding git ignore file
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
$ git status
# On branch master
nothing to commit (working directory clean)
现在对 .gitignore 文件的任何更改都将显示为挂起的更改,tmp 目录之外的任何新文件都将显示为未跟踪的文件,并且 tmp 目录内的任何更改都将被忽略。
不要提交您不想跟踪的文件
如果您已经将 conf.php 添加到您的 git 存储库,则 git 正在跟踪该文件。当它更改时,git会说它有待处理的更改。
解决此类问题的方法是不要提交您不想跟踪的文件。相反,您可以做的是提交默认文件,例如:
$ mv conf.php conf.php.default
$ # Edit conf.php.default to be in an appropriate state if necessary
$ git commit -v -m "moving conf.php file"
$ cp conf.php.default conf.php
现在,您对 conf.php 所做的任何更改都不会显示为未分级更改。