October 9, 2012

Git - Ignore Changes of File in .gitignore List

Sometimes it's common that we tracked some files in the git repository first but later decided not to. For instance in rails application it could be database.yml file. So you added database.yml to .gitignore but when you changed something in that file, git will still show you.

Solution

  1. First added files you don't want to track to .gitignore
  2. Then use either method 1 for single file, or method 2 for folders below.

method 1: git update-index --assume-unchanged

git update-index --assume-unchanged config/database.yml

This works very well with single file, I'm not sure but maybe it doesn't support folder.

Method 2: git rm -r --cached

# This removes everything from the index
git rm -r --cached .

# This will only add files not listed in the .gitignore
git add .
# then commit it
git commit -m ".gitignore is now working"

git - .gitignore file not ignoring - Stack Overflow

Share on Twitter Share the post
Qihuan Piao

Qihuan Piao

(aka kinopyo) is Chinese based in Tokyo. Software writer. He shares stories inspired him in this blog. His infamous line - "I feel calm when I kill those monsters, or people (in game)" shocks his friends deeply.

He also writes in Japanese and Chinese.