Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore files which are in repository?

I have a file (config.php), that is already committed to a Git repository, but I want to ignore locally, i.e. I want that file to remain in repository, but force Git to ignore any changes to it.

I put the file into .gitignore, but it is still marked as changed and Git still is attempting to commit changes to it, every time I commit something.

Any ideas, what am I missing or doing wrong?

like image 855
prcaen Avatar asked Aug 29 '11 14:08

prcaen


People also ask

How do I ignore files in a folder in git?

Personal Ignore Rules Patterns that are specific to your local repository and should not be distributed to other repositories should be set in the . git/info/exclude file. For example, you can use this file to ignore generated files from your personal project tools.

How do I force git to ignore a file?

Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.


3 Answers

If the file is still displayed in the status, even though it is in the .gitignore, make sure it isn't already tracked.

git rm --cached config.php

If you just want to ignore it locally, you could also make it ignored by the git status:

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

As commented, do note that using --assume-unchanged might cause unwanted data loss as git stash resets the "ignored" files to the state in upstream, undoing local changes, without a warning or saving.

like image 105
VonC Avatar answered Oct 12 '22 17:10

VonC


Ignore checked in file:

git update-index --assume-unchanged file

To revert

git update-index --no-assume-unchanged file

Revert All

git update-index --really-refresh 
like image 9
shiva kumar Avatar answered Oct 12 '22 17:10

shiva kumar


If the file is already in the repository, and hence the Index/Staging area, then an update to .gitignore won't change that situation. It would keep being committed.

To remove the file from the Index/Staging area use git rm <file>.

like image 4
Philip Oakley Avatar answered Oct 12 '22 15:10

Philip Oakley