What should I do about user-specific config files

2019-01-15 21:19发布

I've got some config files (.idea/) from an IDE in my working directory, and Git lists these as Untracked files. Should I

  1. add these to the .gitignore (which will get pushed to the main repo), or
  2. use the local option of

    git update-index --assume-unchanged <name of file>
    
  3. or follow a different approach altogether?

What's best practice?

标签: git config
3条回答
趁早两清
2楼-- · 2019-01-15 22:01

Those files are specific to your own machine/setup. You should indeed ignore them.

However, you should not simply add entries corresponding to those files in the project's .gitignore. Instead, you should ignore those files via a global .gitignore:

git config --global core.excludesfile <path-to-global-ignore-file>

Why not just add entries in the project's .gitignore? Remember that this file is going to be used by all collaborators in the project, so you want to keep it clean and tidy; adding user-specific entries to a repository-specific .gitignore will just bloat/pollute the latter, and contribute to unnecessary mental overhead.

For instance, imagine that one collaborator, Bob, works on Mac OS X, whereas another collaborator, Alice, works on Windows. Bob probably wants to ignore .DS_Store files, whereas, Alice probably wants to ignore thumbs.db files. However, Bob has no need to ignore thumbs.db files, and Alice has no need to ignore .DS_Store files. Therefore, they shouldn't inflict a useless gitignore entry on each other. They would do better to ignore such files via a .gitignore file local to their machines.

查看更多
够拽才男人
3楼-- · 2019-01-15 22:09

The .idea folder and its associated .iws, .ipr, and .iwl files are really meant for your machine only. The best practice is to add them to .gitignore.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-15 22:19

IDE specific files should always be ignored. Unless maybe everyone in your team is working with the same IDE, then it might be useful keeping some. But most of the time it's not.

If you choose to 'remove' them locally, there is always the risk of someone forgetting to do that, so it might be best to just put it in a gitignore.

Here is a list of IDE specific gitignore files that you can use
https://github.com/github/gitignore/tree/master/Global

查看更多
登录 后发表回答