.gitignore不能阻止跟踪文件中的更改

17

我在.gitignore文件中忽略的文件,对其做出的修改仍然会被Git跟踪。

文件结构:

.gitignore
wp-config.php
< p > .gitignore 的内容:

wp-config.php

当我修改wp-config.php文件后,运行git status命令时,我会看到该文件已被修改:

alex$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   wp-config.php
#

如何停止跟踪这个文件?我以为把它放在 .gitignore 文件中就足够了。

1个回答

54

通过使用.gitignore,只有未被跟踪的文件会被忽略。

一旦文件被添加,对该文件的更改将不再被忽略。

在这种情况下,您应该使用assume-unchangedskip-worktree

git update-index --assume-unchanged -- wp-config.php
或者
git update-index --skip-worktree -- wp-config.php

1
其他文件怎么办,我需要像这样添加所有其他文件和文件夹吗?而不是添加git ignore? - Naveenbos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接