fail to clean file using git command - xcode

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.

Related

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 not tracking a file from a folder - contents.json from .xcassets

I have checked almost all the questions on SO but nothing has worked for me. The issue that I'm unable commit the Contents.json file of .xcassets whatsoever. Whenever I add new images to .xcassets the source control does list the images but not the Contents.json file. I'm using a bitbucket repository and not even SourceTree is showing this file in the uncommitted changes. Even tried adding all the files via terminal.
git add --all
Any guess why this is happening and what could possibly be the solution?
Update: The .gitignore file looks like:
ProjectName.xcworkspace/xcuserdata
ProjectName.xcodeproj/xcuserdata
*.xcscheme
xcschememanagement.plist
And .git/info/exclude looks something like:
.DS_Store
UserInterfaceState.xcuserstate
A lot of time has passed, but it seems I know what it is. I encountered the same problem, and every time I added resources, I had to manually do the following steps: git add -f
However, I found out about the command: git status --ignored
The command shows all ignored files. After that, I made the git add -f command manually, and it worked.
Probably you have .xcassets/Contents.json in one or more of the three ignore files .gitignore, .git/info/excludes and ~/.gitexclude.
If that is not the case then try executing below command which will ask Git to start tracking the file again:
git update-index --no-assume-unchanged <file>
For your case:
git update-index --no-assume-unchanged .xcassets/Contents.json

Undo a git clean command?

I just used a "git clean" command and managed to delete my Documents, Music, and other directories. Is there a way to undo this and somehow get those files back? I did this via Terminal on Mac. Time Machine isn't setup either.
I'm afraid those files are gone. git clean is not reversible since those files were not tracked by git.
From the comments it looks like you had your home folder as git repo, but with nothing tracked.
Running git clean -f removed any file inside the home folder (included the one in the subdirectories), leaving only empty subdirectories (the -d option is required for removing them too).
I'm sorry to inform you that you definitely wiped out your whole home directory. Next time you run a git clean use the -n options to perform a dry run and check what's going to happen before it's too late.
Unfortunately git clean removes all the untracked files, meaning the files that are deleted are not able to be recovered using git. You might be able to check your trash to see if the files still exist there.

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

Git Ignore Pattern for XCode Build Directory

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).

Resources