Git忽略Xcode项目的文件

Which files should I include in .gitignore when using Git in conjunction with Xcode?


Check https://www.gitignore.io/api/swift,xcode,Cobjective-c,osx

Above link produces an error: gitignore.io/api/swift,xcode,objective-c,osx

You shouldn't be ignoring *.lock or Podfile.lock (never mind the redundancy). You want the exact same versions installed in all workspaces, you don't want the "latest version".

I have removed the Podfile part. I didn't add that originally, SO says someone else added it and I carelessly copy/pasted it into the gist. My apologies for any/all confusion and misunderstanding. I really dislike the way StackOverflow lets anyone edit your answers :(.

There's now an explanation line for EVERYTHING, line by line. This should make it much clearer, and make it easier to customize for your own projects.

Adam As I can see, this file contains VCS metadata, and should therefore not be checked into the VCS. No, there no mentions on developer.apple.com about xccheckout. But on official github page, this file included already in the gitignore file. https://github.com/github/gitignore/blob/master/Objective-C.gitignore

Without official description, we're not going to ignore anything. Almost every time people have done that, it's corrupted someone's project sooner or later. Way too dangerous - don't go there. So I refuse to add anything to this file unless I have a verifiable source confirming it is safe to ignore!

I don't particularly like the .pbxuser/.perspective/*.perspectivev3 patterns. I much prefer the following .xcodeproj/ !*.xcodeproj/project.pbxproj That ignores everything inside a *.xcodeproj except the project.pbxproj.

I do not ignore *.pbxuser, *.perspective and *.perspectivev3 because I like to keep those settings back when I clone my repository.

Also you might want to add that you can make a "global" gitignore file like this: git config --global core.excludesfile ~/.gitignore

I'd like to caution everyone who added .gitignore file after they have committed the project: those files you ignore are still being tracked. You'll have to remove them from git manually using git rm --cached <files>

SpacyRicochet: Comment formatting has apparently changed since I wrote the comment. Hence the italics. My pattern is supposed to look like *.xcodeproj/* !*.xcodeproj/project.pbxproj. Of course, these days you do need to adjust it for workspaces.

I do have the build folder outside of the project folder, but when other users build the project, it by default is recreated in the project- so I found that adding it to the ignore file is a better solution, otherwise it gets readded in their commits.

If you just add xcuserdata, then that takes care of both.

For some reason just adding xcuserdata without the prefix didn't work for me. I thought it should, though. Odd.

Also one of the Github guys has collected some .gitignore files. Here is the Objective-C specific one- github.com/github/gitignore/blob/master/Objective-C.gitignore

Also the Thoughtbot folks came up with this project - github.com/thoughtbot/liftoff which will add a sane default .gitignore files, see their blog post on it: robots.thoughtbot.com/post/33796217972/…

This has already been posted to one of the answers above. I found it to be: incorrect, questionably supported (more than 100 outstanding pull requests!), and undocumented. The fact that it's "incorrect" is the worst of all; they have made an ignore that only works for a narrow set of uses and haven't explained what or why! Hence: my answer above, which corrects their bugs AND explains what's being done and why, so you can make educated decisions on a project-by-project basis (on a new project, I sometimes forget why some of the items are in there - the comments help me decide :))

Adam: GitHub's .gitignore has now been updated for Xcode 6.3.2 and Swift, so it's now correct. It's also documented.

yeah, but the problem with publishing a data-destructive file and keeping it that way for months or years - and apparently not bothering to test it properly - is that you permanently sacrifice all faith, trust, respect from the community. Too late.

always use your example. nice settings! Thanks!

I haven't used gitignore.io for a while - worth checking if you haven't. You can use it to create a gitignore file for whatever IDE / language etc you're using. It'll even add a cocoapods section. Brilliant

Very useful answer. I added it as a link in my Setting Up Github in Xcode answer.

Did you add it also? Or is this just all you do?

Yes, I added both but xcusersate was the main offending file. Adding that was the only way I could push my code remotely. Otherwise I was stuck in a feedback loop that required commit before push. So you commit, then Xcode 4.5 would ask you to commit again and you are never able to push because the pre req is committing.

The github .gitignore file is a collection of all files which we had problems with in the past. Right now, if you start a Xcode project from scratch an let Xcode preconfigure the git repository, there's not too much left to ignore in .gitignore: The only thing I prefer to ignore is xcuserdata/ ... this helps not to clutter your commits.

GitHub is the first place I ever look for gitignores :)

How is this any different to any of the previous answers? Don't just paste your gitignore file here, this does not add anything to this subject.

AshleyMills Please read the answar first then add a comment .... The answar is for a standerd structure / required ones .... which are essentials to have ...