.gitignore doesn't stop changes being tracked in files

白昼怎懂夜的黑 提交于 2019-12-31 08:38:04

问题


Changes I make to a file that's within my .gitignore are being tracked by git.

File structure:

.gitignore
wp-config.php

Contents of .gitignore:

wp-config.php

When I change wp-config.php, and then run git status I see that it has been modified:

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
#

How to I stop tracking this file? I thought putting it in .gitignore would be enough.


回答1:


With .gitignore, only untracked files are ignored.

Once the file has been added, change to that file are not ignored.

In this case, you should use assume-unchanged or skip-worktree instead.

git update-index --assume-unchanged -- wp-config.php

or

git update-index --skip-worktree -- wp-config.php


来源:https://stackoverflow.com/questions/14513854/gitignore-doesnt-stop-changes-being-tracked-in-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!