9

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

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

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

4

6 回答 6

2

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

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

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

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

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

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

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

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

于 2012-06-06T15:25:28.180 回答
1

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

于 2012-04-19T03:41:50.950 回答
0

我们在团队中为避免此文件发生冲突所做的工作是提交除项目文件之外的所有文件。在这种情况下,一切都是安全的。如果您只想要自己的项目文件,则可以避免更新,甚至可以将其包含在.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.
于 2012-06-06T13:55:33.053 回答
0

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

于 2012-04-19T03:38:38.297 回答
0
  1. 退出 xcode
  2. 打开一个终端。
  3. 导航到 /.xcodeproj/project.xcworkspace
  4. 类型:mv contents.xcworkspacedata contents.xcworkspacedata.bak
  5. 重启xcode
于 2012-04-24T13:31:56.567 回答
0

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

于 2014-08-27T09:50:39.830 回答