Random Xcode files are modified/added/deleted in Git - ios

I am using Github desktop to source control my app, but it keeps changing/deleting/adding all sorts of files that I did not touch, assets, pod files, and I do not know what is going on or how to stop it. Any help here?
I re-cloned my repo and still having the issue

They are build artefacts, Pods, and other things you should've excluded from your repo. Use gitignore.io to create a proper .gitignore file, and add it to root folder of your repo (e.g. like this). Then delete all this junk from your repo.
I also recommend reading Apple's guide on working with Source Control

The issue is with iCloud sync, try turning that off

like sfgblackwarkrts already said these "random" files are artefacts, pods etc.
They will be created everytime you made any changes in one of them E.g. updating your pods, changing packages,..
To see how a .gitignore file can be created and managed, you can find a question and the correct answers to it on Stackoverflow.
git - how to create a .gitignore file

Related

project.pbxproj is always tagged as modified in git

I'm having some problems with xcode, with disappearing linked libraries, etc.
After some research, it seems that my project.pbxproj file has been completely changed in between two commits, and I'm trying to restore an older version. However, and it has been some time now, my project.pbxproj is always flagged by git as modified. I've always figured it was XCode modifying the file at the same time I was modifying some things in the GUI. However, for the first time, git is keeping me from merging, or reverting, due to changes to this file. I can't gitignore it as it contains vital information necessary to build my project.
It gets weirder, though, as the file is indeed always in a modified state. I just tried booting my mac with absolutely no app open, no IDE, not xcode, and just opening a terminal, to clone my project in a newly created folder. After cloning, if I just cd into the folder and git status, the file is flagged as modified.
Is this behavior normal? Have people experienced issues with this file and git? Can i revert my project.pbxproj to an older state, and is it safe to do so? Are there some git configurations that I can use to better handle this file?
My project isn't native, I'm using the react-native framework
The file project.pbxproj is constantly changing since it contains information about the structure and configuration of the project, linked frameworks and more.
i found that adding *.pbxproj binary merge=union in my .gitattributes fixed 95% of my merge problems in that file, there is always one rare case where the union fails and you end up with bad closing brackets, but is usually easy to find and fix it manually.
I've understood what was my problem and I'll expose it here, then leave it to moderation to see if it is relevant, as this situation might happen to other people.
I have, months ago, changed my package name on Xcode, removing some capital letters, as an application of my understanding that packages names shouldn't include capital letters. The name went from com.mycompany.MyApp to com.mycompany.myapp. As a result, XCode deleted the MyApp.xcodeproj folder and created a myapp.xcodeproj folder (I think it was automated, but can't be sure, as this happened a few months ago).
All went well in this regard, except git kept trace of both folders in the repository. Whenever I would clone my repository, I would get a myapp.xcodeproj folder, but git would still consider there was both myapp.xcodeproj and MyApp.xcodeproj in the repository.
This led to git comparing different files in local and remote, therefore systematically considering this file as modified, even if it was just committed, or even pushed. Git always was comparing the current version of the file with one that was 2 months old. The behavior was erratic, as the myapp folder was always flagged as modified, and actually modifying it would flag MyApp folder as modified as well.
Hope this might help someone someday.
I'll answer my own questions:
Is this behavior normal? Absolutely not
Have people experienced issues with this file and git? Yes, human merging of this file is difficult and I wouldn't recommend it. To avoid having to do so, Javier Rivarola's answer as well as this question might help you
Can i revert my project.pbxproj to an older state, and is it safe to do so? You will lose the configuration you've done after that, but the file stays valid
Are there some git configurations that I can use to better handle this file? see second question

Create a new Xcode project in an existing Git repo

I have an iOS app I was writing using React Native until I realized React Native wouldn't fit my needs and I'd need to write the app with Xcode. Because my original project is already in a repo on GitHub, I'd like to use my existing Git repo for the new Xcode project.
I'm new to IDEs and a little scared that if I just move the files over something will get messed up and I won't know how to fix it. Is there a more orthodox way to do this? I've googled this and have come up with lots of advice for adding a new Git repo to an existing Xcode project, but not the other way around.
I appreciate any help I can get!
Simply create a new Xcode project and choose to create it in the same folder on your Mac that is the local copy of the repo.
Deselect the option that says "Create Git repository on my Mac".
This will effectively show up in your local repo as a bunch of files that were added—even an empty Xcode project contains several files.
Xcode will just use the existing repo setup that was already there. So naturally the first step after creating the project would be to commit the Xcode project.
(NB. there is no "rule" that a single repo can not house various projects or "things", although in practice you would often create a fresh repo for the new thing instead of throwing everything together in one)

Remove SVN repository refrences in XCode5

I am facing some issues while importing files to my project. When I import these files which are already linked to another repository it contains the references of old repository and I am unable to Commit/Add these files to new repository. I tried other solution like searching for .svn files in the folder and deleting them and also through command line tool but i am not able to remove the references of old repository.
Please suggest some solution for this.
Thanks
I think you can check out this answer in superuser, from my personal experience this is the only way of doing it. Here is the link to the answer:
https://superuser.com/questions/388020/how-to-use-terminal-to-delete-all-svn-folders-recursively
The only way that I know is to delete all .svn files from ALL sub-directories. Maybe you can create/find a script for doing this job.
In any case, if there is a better way to import the project linked to another repository, I would be happy know as well.

How do I incorporate a custom control from github to my project and stay up to date

I use a couple of custom controls from github, thus far I've always added source code files as new resources to my project in XCode. But I have now seen this repo getting updated frequently, it made me wonder if I can add source files and get them updated (manually or automatic) when something new is pushed. Sorry it might be a noob question.
This is the repo : BlockAlertsAnd-ActionSheets
Sounds like you want a git submodule.
As far as I know, there's no way to do this within Xcode, so you'd need to do this from the command line.
And if you're comfortable with using git via the Terminal command line, here's a tutorial on how to get this set up.
you can use CocoaPods. and there is a pod for this repo.
it's really useful to manage your dependencies. to get a new version of a pod, you'll need just update your Podfile and run 'pod install'. Check the website, you'll find more info there.

Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file

I was trying to merge branches and it resulted in the error "Unable to open project… cannot be opened because the project file cannot be parsed". I then tried to take the advice of other stackoverflow responses (namely to edit the file to remove the corruption), but was unable to edit the file. It appears that this is actually a directory, so maybe the structure of this changed with version 4.4 of xcode and since the response to Unable to open project... cannot be opened because the project file cannot be parsed was written.
I then tried to restore myProject.xcodeproj from my time machine backup. This does not work because it says that I don't have permission to access myProject.xcodeproj. I tried to change the permission of that directory, but that did not help.
I closed and reopened xcode. Now the error is:
Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file.
How can I fix this problem in xcode version 4.4? Can it be restored from the previous snapshot or archive or version in xcode. Can it be restored with time machine. I would like to avoid rebuilding the entire project.
The simplest thing to do is probably to
Checkout myProject.xcodeproj from source control. This will contain the changes that were causing you to be in conflict last time.
Redo the project changes that you made since the last time you committed to source control
commit/push to source control.
In the future, when you get a conflict in the project file, take a look at myProject.xcodeproj/project.pbxproj. Often it's just new files in the project that have been added at the same place. In this case you just need to delete the conflict metadata and resolve the conflicted state.
In the end, what I had to do was
'cp -R ...TimeMachineBackup/myProject.xcodeproj ...myProjectArea/myProject.xcodeproj'
Then I had to do the following in myProjectArea:
git reset --merge
This allowed me to open the project and switch branches back to my main branch.
not a pleasant experience
Another way this can happen is if you've been using sudo for some reason with pods or the editor - if the file exists under yourApp.xcodeprojectroj directory but xcode is complaining it can't find it - Go to your project root and do:
sudo chown -R yourusername:staff ./*
For others looking at this issue, the cause in my case turned out to be, that the "conflict text" from a git merge had crept into the actual file:
<<<<<<< HEAD
F0FDA2D61B99EB80007DB99D /* Aptron-mCollegix.xcassets */,
=======
F08CFAAA1BC1E9EE00A5B6F5 /* Aptron-mCollegix.xcassets */,
>>>>>>> hotfix/Column_Text_Cut-off
opening the project.pbxproj in a text editor made the fix easy.
I found my own solution to this issue.
The cause of the bug is that the .xcodeproj file is missing its containing pbxproj file, right? This is usually present when you right click your .xcodeproj file and click 'Show Package Contents'. However, in your own case, it's been deleted, through some mistake or other of git versioning.
As you can't really generate a .pbxproj file, the solution I found was to go to the original project folder location, which I had used to create the repository. To be honest, you could probably simply create a new project also, as long as it has the same bundle identifier and such! As this project's xcodeproj file will correctly contain a .pbxproj file, replacing the files in the XCode environment with your own project's files will allow the .pbxproj file to update based on these files.
Therefore, after opening this original project folder (/new project folder), in the XCode environment, I then removed all the files within the project, and replaced them with the corresponding files from my project which I was unable to open the xcodeproj file of. I had to fix a few resulting bugs here and there, stuff involving build phases and such not lining up, given you've just copied in a bunch of new files. But after fixing a few small errors, the same project in this new location was eventually able to run no problem!
Finally, I took this successfully running version of the project, and copied in all the files, .xcodeproj file, project folder, test files and all, into the original repository location, deleting the files from the repository before hand to avoid confusing overwriting of files (you can cut and paste the old repository files to a new location if you want to be safe, and don't fancy deleting them!). Then open the project in XCode from the repository location, build and run it on your simulator/device to make sure everything lines up (and fix any small bugs you may need to), and voila! Your project is now able to be committed, pushed, and ran!
This isn't the cleanest solution, and you may have to do similar things across various branches if they've all been corrupted. However, if you don't have access to a Mac time machine, and the other solutions aren't working for you, this is possibly the most straight forward way of having a working .pbxproj file again!
Oh, and I removed the .pbxproj from my gitignore. I'm not sure if it's actually find to have it in your gitignore or not, but I'd recommend doing your own research on that subject, I'm not certain myself!
Good luck!
I was able to get this working without commandline stuff like this:
Go to Time Machine drive in Finder.
Navigate to desired backup.
Drag it to where I want it. This will complain about not having permission to access the .pbxproj
Right-click the xcodeproj you just dragged out, select "Show Contents".
Right-click the xcodeproj in the Time Machine backup folder, select "Show Contents".
Drag the .pbxproj you see inside to the destnation you just created with the drag in #3.
Now it should work.
It seems you can generate the file again with:
swift package generate-xcodeproj
although you could see this message:
warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
generated: ./BokenEngine.xcodeproj
with xcodebuild > 13.4.1:
xcodebuild -version
Xcode 13.4.1
Build version 13F100
If anyone wants to find the missing project.pbxproj file then try opening the .xcodeproj with some code editor and you will find the file there. And note that i had backup of my application in my other pc so i found that file there so you mist have backup of your project somewhere in order for this to work.
In my case the issue was that there were actually 2 folders with .xcodeproj suffix
The actual one was located in MyApp/MyApp.xcodeproj
Somehow another one with the same name MyApp.xcodeproj got added to root folder, with the following contents:
project.xcworkspace/contents.xcworkspacedata
project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
So deleting this corrupt(?) xcodeproj solved the issue.

Resources