Git Ignore Pattern for XCode Build Directory - xcode

I am new to Git, and this is my first project using Git rather than SVN as my source control. I am working in XCode on an iPhone project. I want Git to ignore the build directory, which is in the root folder of the XCode project. I've found several other questions here and also found articles on google that provide examples on how to create the .gitignore file in the root directory and then add it to the Git repository to get the directory to be ignored.
Here are the steps I'm taking when setting up the repository:
Open Terminal and navigate to the root directory of the application
Call git init to initialize the repository
Call git add .gitignore to add the gitignore file
Call git commit -m to commit the gitignore file
Call git status to view the status of the repository
At this point, all of the other directories and files listed in my gitignore file are properly ignored except the build directory. Here is what my gitignore file looks like:
build/
.DS_Store
**/*.pbxuser
*.mode2v3
*.mode1v3
**/*.perspectivev*
I have tried ignoring the build directory using the following different entries with no success:
build
build/
build/*
Anyone know what I'm doing wrong here?

build/ or build/* should be enough to ignore the directory.
See also "Difference between .gitignore rules with and without trailing slash like /dir and /dir/"
The only reasons it could be still not ignored at this point if it:
has somehow been added to the index and committed (which, according to your setup, shouldn't be the case)
has a trailing space (/build ) in the .gitignore file rule, as in this .gitconfig, before Git 2.0 (Q2 2014).

Related

fail to clean file using git command

After merging, I checked with git status and cleaned with git clean -rf, but I was still left with the following untracked file:
<projectName>.xcodeproj/xcuserdata/<username>.xcuserdatad/xcdebugger/
I then checked to see if it would be cleaned with git clean -n, and there was nothing shown, as expected (since it was not cleaned in the previous command).
Also, I have tried an alternative, that I touch .gitignore and added xcuserdata in the .gitignore file. Afterwards when I checked for git status, the untracked file becomes .gitignore, effectively substituting the previous untracked file, which still did not really solve my problem.
What should be the way so that I can clean up my working tree?
It seems the directory is generated by xcode when xcode is running. Close xcode and try git clean -df in the console. If it can be removed properly, add it to .gitignore.
To ignore .gitignore itself, you can add the line .gitignore to the file .gitignore. Another solution is to add and commit .gitignore.

Xcode .gitIgnore showing shows files with ignored folder

I have tried to solve this by
Deleting all pods and re installing
Cleaning build folder
Deleting .gitignore and recreating
However there are a few files within the Pods dir that continue to show up
I'm ignoring using this in my .gitignore since my initial commit - nothing in this has ever been committed.
Pods/
Note this has only started recently with a with a new pod update
When I try to commit I get the following.
All other pods within this dir are ignored.
I have looked at these, but no luck fixing
.gitignore ignoring whitelisted folder
.gitignore not ignoring folder
Gitignore not ignoring folders
.gitignore doesn't ignore files
This looked like it may have the solution but not sure if I want to try it, so decided to post and understand the reason why this is happening
gitignore does not ignore folder
Note: Running Swift 4.2 / Xcode 10.1
You were tracking this files so they are added to index. All you have to do before ignoring this files you have to untrack them.
If you want to remove them from the index you have to type git rm -r --cached {name_folder} then use git commit -m "removed files from index" and change your .gitignore file.

Git Ignore Basics

I am very new to Git and am trying to use a .gitignore file. I have an Xcode project which includes many CocoaPods and Nodejs modules. I want all these files to be ignored, but I'm not sure how to create a .gitignore file and how to specify which files to ignore. Somebody please help.
First, you can simply copy a .gitignore file from gitignore.io:
https://www.gitignore.io/api/xcode
Second, make sure those files were not already added to the index.
Do a git check-ignore -v -- a/file/I/want/ignored: if it returns nothing, then remove it from the index (git rm --cached a/file/I/want/ignored) and try again.

What should I include in the .gitignore file for Swift playgrounds?

I want to use Git for versioning my playgrounds, but I am not sure which files should be ignored and which ones I should commit.
Currently I use following .gitignore file for playgrounds:
# Xcode user data
xcuserdata
What else should be there?
From the official github gitignore for Swift
## Playgrounds
timeline.xctimeline
playground.xcworkspace
Whether it is a normal project or playgrounds, it is convenient and useful to use one of the standard .gitignore files for Swift. From the terminal cd into your project root folder (the one with the .xcodeproj file for a normal project) and run the following command:
curl -o .gitignore https://www.gitignore.io/api/swift
Or alternatively get it from the GitHub source:
curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Swift.gitignore
You can edit the file to make changes if you need to. I just use the defaults.

Git not ignoring certain Xcode files in .gitignore

I am new to Git and I am using it to backup an iPhone project I am working on.
I have added a list of files that Git should ignore (xcode files) when I update, but this .perspectivev3 (which is in my .gitignore) file keeps showing up when I go to commit my changes. Does anyone know why this is, or what I am doing wrong?
Thanks,
Zach
This is what is in my .gitignore file:
# xcode noise
*.mode1v3
*.pbxuser
*.perspective
*.perspectivev3
*.pyc
*~.nib/
build/*
# Textmate - if you build your xcode projects with it
*.tm_build_errors
# old skool
.svn
# osx noise
.DS_Store
profile
If it keep showing up in the git status, it must have been added or committed before.
You need to
git rm --cached that file, in order for the git status to not list it anymore (it is was just added, but not committed yet).
git rm that file, if it was previously committed (see this question for instance)
You can use
$ git rm --cached ./whatever1.txt
after something is already under version control.
In fact, if you have "whatever1.txt" under version control and you want to remove it from git, but leave your working tree undisturbed, then just do this:
$ git rm --cached ./whatever1.txt
$ echo /whatever1.txt >> ${PROJECT_ROOT}/.gitignore
$ git status # this will now show ./whatever1 as "deleted" (from git, not your working tree, and will show gitignore as modified or created)
$ git commit -a
And that's it.
Only use
$ git rm
when you want to remove the file from both the working tree AND the git repo.
CAVEAT: The likely scenario you would use this is for removing IDE-specific files from git. In this example "whatever1" represents your IDE file(s) you're removing. If you are working on a project with several people and you push this changeset to a shared repo, then their "./whatever1" files WILL BE DELETED when they pull this changeset. The easy thing to do from here for the people on the receiving end is:
$ git checkout 1215ef -- ./file-you-want-to-restore ./another-file ./another-etc
(where 1215ef represents the last commit before the deletion)
This has the effect of restoring those files that were present at their last commit before the pull. After they have done this those files will be safe and not show up as uncommitted b/c they will fall under the exclusion of gitignore.
Good luck!
.gitignore only applies for untracked files. If you've git-add'ed files that are otherwise untracked due to .gitignore, they will still be part of the repository.
Simply remove the files from the repository you don't want anymore:
git rm *.perspectivev3

Resources