git update-index
does the job for me:
git update-index --assume-unchanged <file>
Note: This solution is actually independent on .gitignore
as gitignore is only for untracked files.
Since this answer was posted, a new option has been created and that should be preferred. You should use --skip-worktree
which is for modified tracked files that the user don't want to commit anymore and keep --assume-unchanged
for performance to prevent git to check status of big tracked files. See https://stackoverflow.com/a/13631525/717372 for more details...
git update-index --skip-worktree <file>