【问题标题】:How to avoid modifying the project file ( .xcodeproj ) of Xcode frequently worked on by team?如何避免修改团队经常工作的 Xcode 的项目文件( .xcodeproj )?
【发布时间】:2012-04-30 13:19:57
【问题描述】:

与 Eclipse 或其他 IDE 不同,Xcode 会在发现项目中的文件或组被添加、重命名或删除时修改 .xcodeproj 文件。当项目中有多个开发人员时,这非常不方便。

一旦我的 SCM 工具抱怨 .xcodeproj 文件存在冲突,我所能做的就是检查整个项目的另一个副本并将我所做的所有更改合并到其中并祈祷没有人比我“更快”。

有没有办法改变Xcode的默认策略?

【问题讨论】:

    标签: iphone ios xcode macos


    【解决方案1】:

    与 Eclipse 或其他 IDE 不同,Xcode 会在发现项目中的文件或组被添加、重命名或删除的任何时候修改 .xcodeproj 文件。

    与 Eclipse 和其他一些 IDE 不同,Xcode 维护项目中包含哪些文件的列表以及作为项目“文件”的一部分的组结构(.xcodeproj 文件实际上是一个目录)。这些组不必以目录的形式物理存在,文件实际上可以位于各种位置,并且不必像在 Xcode 中那样命名。

    如果有人将新文件添加到项目中,或者从项目中删除文件,或者更改文件或组的名称,则需要在您的 SCM 中反映出来,因为其他人检出工作副本或克隆如果项目与磁盘上的内容同步,您的存储库或任何更喜欢它的东西。因此,例如,如果有人删除了一个文件,但该更改未反映在其他人的 Xcode 项目文件中,则他们在 update/sync/pull 或其他任何操作后会出现编译错误。

    话虽如此,项目文件还包含大量不重要的用户设置。在 Xcode 4.x 中,我将以下目录设置为被我的 SCM 忽略:

    foo.xcodeproj/project.xcworkspace/xcuserdata
    foo.xcodeproj/xcuserdata
    

    在早期版本的项目文件中,我曾经将以下内容设置为忽略:

    foo.xcodeproj/*.pbxuser
    foo.xcodeproj/*.mode1v3
    

    就 SCM 而言,这似乎过滤掉了不必要的废话。

    【讨论】:

      【解决方案2】:

      据我了解,.xcodeproj 实际上是多个文件的包装器,包括 .pbxuser 和 .pbxproj。不知道您使用的是什么 SCM,但是对于那些使用 git 的人来说,这个话题在 here 上被触及,并且共识似乎是 .pbxuser 文件以及许多其他文件不应该包含在版本控制之下。

      【讨论】:

        【解决方案3】:

        这不是你唯一的办法。 .xcodeproj 文件是文本。格式不是太难理解。解决冲突的常用方法是同时添加两组(当然也有例外)。

        【讨论】:

          【解决方案4】:
          1. 退出 xcode
          2. 打开一个终端。
          3. 导航到 /.xcodeproj/project.xcworkspace
          4. 类型:mv contents.xcworkspacedata contents.xcworkspacedata.bak
          5. 重启xcode

          【讨论】:

            【解决方案5】:

            我们在团队中为避免此文件发生冲突所做的工作是提交除项目文件之外的所有文件。在这种情况下,一切都是安全的。 如果您只想要自己的项目文件,则可以避免更新,甚至可以将其包含在 .gitignore 文件中,以便自动忽略它。

            #########################
            # .gitignore file for Xcode4 / OS X Source projects
            #
            # Version 2.0
            # For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
            #
            # 2013 updates:
            # - fixed the broken "save personal Schemes"
            #
            # NB: if you are storing "built" products, this WILL NOT WORK,
            # and you should use a different .gitignore (or none at all)
            # This file is for SOURCE projects, where there are many extra
            # files that we want to exclude
            #
            #########################
            
            #####
            # OS X temporary files that should never be committed
            
            .DS_Store
            *.swp
            *.lock
            profile
            
            
            ####
            # Xcode temporary files that should never be committed
            #
            # NB: NIB/XIB files still exist even on Storyboard projects, so we want this...
            
            *~.nib
            
            
            ####
            # Xcode build files -
            #
            # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"
            
            DerivedData/
            
            # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"
            
            build/
            
            
            #####
            # Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
            #
            # This is complicated:
            #
            # SOMETIMES you need to put this file in version control.
            # Apple designed it poorly - if you use "custom executables", they are
            # saved in this file.
            # 99% of projects do NOT use those, so they do NOT want to version control this file.
            # ..but if you're in the 1%, comment out the line "*.pbxuser"
            
            *.pbxuser
            *.mode1v3
            *.mode2v3
            *.perspectivev3
            # NB: also, whitelist the default ones, some projects need to use these
            !default.pbxuser
            !default.mode1v3
            !default.mode2v3
            !default.perspectivev3
            
            
            ####
            # Xcode 4 - semi-personal settings
            #
            #
            # OPTION 1: ---------------------------------
            # throw away ALL personal settings (including custom schemes!
            # - unless they are "shared")
            #
            # NB: this is exclusive with OPTION 2 below
            xcuserdata
            
            # OPTION 2: ---------------------------------
            # get rid of ALL personal settings, but KEEP SOME OF THEM
            # - NB: you must manually uncomment the bits you want to keep
            #
            # NB: this is exclusive with OPTION 1 above
            #
            #xcuserdata/**/*
            
            # (requires option 2 above): Personal Schemes
            #
            #!xcuserdata/**/xcschemes/*
            
            ####
            # XCode 4 workspaces - more detailed
            #
            # Workspaces are important! They are a core feature of Xcode - don't exclude them :)
            #
            # Workspace layout is quite spammy. For reference:
            #
            # /(root)/
            # /(project-name).xcodeproj/
            # project.pbxproj
            # /project.xcworkspace/
            # contents.xcworkspacedata
            # /xcuserdata/
            # /(your name)/xcuserdatad/
            # UserInterfaceState.xcuserstate
            # /xcsshareddata/
            # /xcschemes/
            # (shared scheme name).xcscheme
            # /xcuserdata/
            # /(your name)/xcuserdatad/
            # (private scheme).xcscheme
            # xcschememanagement.plist
            #
            #
            
            ####
            # Xcode 4 - Deprecated classes
            #
            # Allegedly, if you manually "deprecate" your classes, they get moved here.
            #
            # We're using source-control, so this is a "feature" that we do not want!
            
            *.moved-aside
            
            
            ####
            # UNKNOWN: recommended by others, but I can't discover what these files are
            #
            # ...none. Everything is now explained.
            

            【讨论】:

              【解决方案6】:

              作为一种避免合并的策略冲突:如果两个用户在同一位置更改文件,您将遇到需要痛苦的手动合并的冲突。例如,如果两个用户在组的末尾添加一个文件,就会发生这种情况,因为这两个更改都在同一个地方。如果每个人都在不同的位置添加新文件(例如按字母顺序),则不会有合并冲突。或者至少更少。

              【讨论】:

                猜你喜欢
                • 2011-06-12
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-05-30
                • 1970-01-01
                • 2015-07-12
                相关资源
                最近更新 更多