0

For example we have local repository with .gitignore content:

/.env.*.local
/public/bundles/
/var/
/vendor/

and global .gitignore from git config:

.idea/
setup_done.lock

As we can see in my global .gitignore we have ignored directory .idea/ but repo comes with this directory and when I'm working in my IDE, it's making changes in these files and want to commit them.
Is it possible to "hard override" repo's .gitignore and do not track changes in .idea/ directory?

Damian
  • 525
  • 2
  • 11
  • 24
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – Michał Politowski Oct 16 '19 at 08:14
  • The problem is not that your global gitignore is being overridden, it's not. Both ignore files will apply to this repository. The problem is that `gitignore` files only apply to files that are not in the repository. Once those files have been committed, git will always track them. – Edward Thomson Oct 16 '19 at 10:13

2 Answers2

0

You can do this, assuming no files are being added/removed and no subdirectories are present (source):

git update-index --assume-unchanged .idea/*

However, be sure to also read and understand IDEA's documentation about what to commit from .idea.

Thomas
  • 174,939
  • 50
  • 355
  • 478
0

There is no way to make Git ignore changes to files that are tracked. Some people will tell you to use the --assume-unchanged or --skip-worktree flags to git update-index, but these do not work in all cases, aren't designed for this purpose, and aren't supported upstream for this.

In general, configuration files for specific editors don't belong in version control because users will use different configurations. The best way to handle this is to remove the .idea directory from version control and use static, editor-neutral configuration such as .editorconfig files. Once you do this (e.g., with git rm --cached .idea), your gitignore will be honored, since Git will no longer track configuration.

bk2204
  • 64,793
  • 6
  • 84
  • 100