Git源码控制下IntelliJ IDEA项目文件不断变化如何处理? [英] How to deal with IntelliJ IDEA project files under Git source control constantly changing?

查看:58
本文介绍了Git源码控制下IntelliJ IDEA项目文件不断变化如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们团队中的每个人都使用 IntelliJ IDEA,我们发现将其项目文件(.ipr 和 .iml)放入源代码管理中很有用,以便我们可以共享构建配置、设置和检查.此外,我们可以在 TeamCity 的持续集成服务器上使用这些检查设置.(我们在 .gitignore 文件中有每个用户的工作区 .iws 文件,而不是在源代码管理中.)

Everyone on our team uses IntelliJ IDEA, and we find it useful to put its project files (.ipr and .iml) into source control so that we can share build configurations, settings, and inspections. Plus, we can then use those inspection settings on our continuous integration server with TeamCity. (We have the per-user workspace .iws file in the .gitignore file and not in source control.)

但是,当您在 IDEA 中执行任何操作时,这些文件的变化很小.IDEA 的问题数据库中有一个问题 (IDEA-64312),所以也许有人可能会将此视为 IDEA 中的一个错误,但在可预见的未来,我们仍需要忍受它.

However, those files change in little ways when you do just about anything in IDEA. There's an issue in IDEA's issue database for it (IDEA-64312), so perhaps one might consider this a bug in IDEA, but it's one we'll need to live with for the foreseeable future.

直到最近,我们还在使用 Subversion,但我们最近切换到 Git.我们每个人都刚刚习惯于拥有一个我们忽略的项目文件更改列表,除非有我们想与他人共享的项目文件更改,否则不会签入.但是对于 Git,真正的力量似乎是(从我们正在探索的内容来看)它鼓励的连续分支,并且在分支之间切换是一种痛苦,因为项目文件总是被修改.通常它可以以某种方式合并更改,并尝试处理现在应用于新分支的项目文件更改.但是,如果新分支更改了项目文件(例如该分支正在处理一个尚未在其他分支中的新模块),则 git 只会抛出一个错误,表明合并文件没有任何意义当分支都有变化而你在本地也有变化时,我更能理解它的意思.从命令行,可以使用-f"在git checkout"上命令强制它抛出本地更改并使用分支的代替,但是(1)IDEA(10.5.1)中的Git Checkout GUI命令似乎没有作为我们可以找到的选项,所以我们d 需要定期切换到命令行,并且 (2) 我们不确定我们是否希望养成使用该标志并告诉 Git 丢弃我们本地更改的习惯.

Up until recently, we were using Subversion, but we recently switched to Git. We had each just gotten used to having a change list of project files that we ignored and didn't check in unless there were project file changes that we wanted to share with others. But with Git, the real power seems to be (from what we're exploring) the continuous branching that it encourages, and switching between branches is a pain with the project files always having been modified. Often it can just merge in the changes somehow, and tries to deal with the project file changes now being applied to the new branch. However, if the new branch has changed project files (such as the branch is working on a new module that isn't in the other branches yet), git just throws an error that it doesn't make any sense to merge in the files when both the branch has changes and you have changes locally, and I can rather understand its point. From the command line, one can use "-f" on the "git checkout" command to force it to throw out the local changes and use the branch's instead, but (1) the Git Checkout GUI command in IDEA (10.5.1) doesn't seem to have that as an option that we can find, so we'd need to switch to the command line on a regular basis, and (2) We're not sure we want to be in the habit of using that flag and telling Git to throw out our local changes.

因此,以下是我们对必须处理此问题的选项的一些想法:

So, here are some thoughts we have on options we have to deal with this:

  1. 使项目文件完全脱离源代码控制.将它们放在 .gitignore 中,并通过其他方式将它们分发给每个人和 TeamCity,可能是通过将它们放在其他地方或其他名称的源代码管理中.我们的团队足够小,这个选项足够可行,可以考虑,但看起来不太好.
  2. 继续使用它,尝试确保在给定时间管理我们在哪些分支上拥有哪些文件.作为其中的一部分,我们可能会鼓励每个开发人员在他们的系统上拥有每个项目的多个副本,这样他们就可以将每个项目签出到不同的分支,其中可能包含不同的项目文件集.
  3. 尝试在源代码管理中只使用项目 (.ipr),模块 (.iml) 文件不在源代码管理和 .gitignore 文件中.似乎定期在 .ipr 中自行切换的主要内容是共享构建配置的顺序,但也许我们可以单独共享有关如何设置这些配置的信息.我不太确定 IDEA 如何处理这种只有部分文件的事情,尤其是在新结帐时.

我想我希望我们错过了一些明显(或不明显)的解决方案,也许是处理 Git 和 IDEA 似乎都具有的巨大可定制性.但看起来我们不可能是唯一有这个问题的团队.Stack Overflow 上类似的问题包括 349519110005123873872,但我不知道,因为它们完全相同问题,也许有人可以针对我概述的各种方法、这些问题的答案中列出的方法或他们推荐的方法提出优缺点.

I guess I'm hoping there's some obvious (or non-obvious) solution we've missed, perhaps dealing with the huge customizability that Git and IDEA both seem to have. But it seems like we couldn't possibly be the only team having this problem. Questions that are kind of similar on Stack Overflow include 3495191, 1000512, and 3873872, but I don't know as they're exactly the same issue, and maybe someone can come up with the pros and cons for the various approaches I've outlined, approaches listed in the answers to those questions, or approaches that they recommend.

推荐答案

您可以使用 IDEA 的 基于目录的项目结构,其中设置存储在 .idea 目录而不是 .ipr 文件中.它提供了更多 对版本控制中存储的内容进行细粒度控制..iml 文件仍然存在,因此它不能解决其中的随机更改(也许让它们不受源代码控制?),但是共享诸如代码样式和检查配置文件之类的内容很容易,因为它们中的每一个在 .idea 目录下它自己的文件中.

You can use IDEA's directory-based project structure, where the settings are stored in .idea directory instead of .ipr file. It gives more fine-grained control over what is stored in version control. The .iml files will still be around, so it doesn't solve the random changes in them (maybe keep them out of source control?), but sharing things such as code style and inspection profiles is easy, since each of them will be in its own file under the .idea directory.

这篇关于Git源码控制下IntelliJ IDEA项目文件不断变化如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆