Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore doesn't stop changes being tracked in files

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.

like image 444
Alex Avatar asked Jan 25 '13 01:01

Alex


People also ask

Why is .gitignore not ignoring my files?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them. Igal S.

Does Gitignore ignore tracked files?

gitignore file prevents future untracked files from being added to the git index. In other words, any files that are currently tracked will still be tracked by git.

How do I turn off tracking in Gitignore?

gitignore . If you pull from a remote and that remote has changes to this path, git will fail the merge with a conflict and you will need to merge manually. git rm --cached <path> … will cause git to stop tracking that path.

How do I turn off track changes in git?

The . gitignore will prevent files that Git does not track from being added to the set of files that the version control system is tracking. On the other hand, Git will not stop tracking a file that is already being tracked, even if you add it to .


1 Answers

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
like image 114
linquize Avatar answered Oct 17 '22 08:10

linquize