Xcode git can't ignore all *.xcodeproj/xcuserdata/ folders - xcode

I followed cant-ignore-userinterfacestate-xcuserstate and ignore-files-that-have-already-been-committed-to-a-git-repository. But these never works.
My Step Reproduction:
Quit Xcode
project directory: git rm -r --cached .
project directory: git add . && git commit -m "remove junk files"
Open Xcode project
Then these files appear again.
Most troubled me was that each time I rebase code will automatic appear these files so I will rebase fail of unstage files. Each time I need to stash these file.
This is my .gitignore file code section:
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
*.xcodeproj/xcuserdata/

I just realized that these want to ignored files was buried in deep folder.
And git don't support this kind of pattern *.xcodeproj/xcuserdata/.
Want to ignore other son son (recursive) folder need add this to .gitignore:
ios/**/*.xcodeproj/xcuserdata/
or a clean way:
**/xcuserdata/
This **/*.xcodeproj was git version 1.8.2's feature.
$ git --version
git version 2.16.1
So most of us can use it.
I learnt from how-to-gitignore-files-recursively.

Related

What is the purpose of pom.properties in STS?

Hi, I'm making a Spring project now with STS and Git.
However, whenever I try to do Git Push,
I discover that pom.properties file that I've never worked on is always automatically modified.
1.
So I always ignore it by Git Stash clear or Git Reset.
Is it a smart action?
2.
By the way, what is the purpose of pom.properties file?
I've tried to find the answer on the net, but I couldn't.
Spring help guide also doesn't give me the answer.
I'd be happy if I can get your answer.
As seen in "Version Informations Into Your Apps With Maven", this file would be used to show a version information in a kind of About Dialog or may be on command line as well.
That file is created by an archive step.
If you wanted to ignore it, you could do:
git rm --cached pom.properties
echo pom.properties>>.gitignore
git add .gitignore
git commit -m "Ignore pom.properties"
git push
That way, the file would still be generated/modified, but would no longer be tracked by your Git repository.
As commented by Ralph, the all target folder should not be in Git (since it can be rebuilt every time)
git rm -r --cached target
echo target/>>.gitginore
git add .gitignore
git commit -m "Ignore target folder"
git push

Why are "ghost" folders with a weird "\200" character appearing in git? [duplicate]

This question already has answers here:
Remove a file with a strange name from git
(3 answers)
Closed 7 years ago.
TL;DR summary
Weird files appeared. They show on git but not on disk. A list of possible programs causing that are listed.
Why did they appear?
How can I get rid of them now?
There is a weird \200 character I cannot type.
For the record: the solution that worked for me is the second answer of user VonC: https://stackoverflow.com/a/13250936/1255826
I already had to copy all the files and make a new Git repository, removing the .git folder from my project to try and fix this. git status claims there are modified files/folders with a very strange \200 character in their name, when actually I didn't add those.
To clarify, I cannot see any file with those names on my disk. I can only assume there is something weird going on in the .git folder. I've tried to see if there are any hidden files with that \200 part in their name. There aren't. (I even have the "show hidden files and folders" option enabled on my computer):
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls
es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls -ahf
. .. es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$
See my terminal log here to see exactly what I mean.
Note that git status didn't show these files, that were added a second later when I used the git add -A command. Then, after that, these "ghost" files are shown:
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
Untracked files:
(use "git add <file>..." to include in what will be committed)
laboratorio/lab5/es3/.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git add -A
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: laboratorio/lab5/es3/.gitignore
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
new file: "laboratorio/lab5/es3/src\200student/student.c"
new file: "laboratorio/lab5/es3/src\200student/student.h"
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
deleted: "laboratorio/lab5/es3/src\200student/student.c"
deleted: "laboratorio/lab5/es3/src\200student/student.h"
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$
I've already tried in the past to ignore this, and push the changes to github anyway, but then the same files/folders are shown in github, although when I click them I get an error page (404 or 500, I don't remember the error code).
Also, if I try to delete these with a del or rm command, it says the file doesn't exist. I don't even know if I can type the character that stands for the \200 escape code.
I might have to try and type that character when I use git rm <PATH/TO/FILE> instead of just trying to do del or rm, that do not work.
Why are these files/folder being created? Is it just a bug?
I'm working with a combination of these tools and programs: cygwin64, mingw64, gcc, make, splint, netbeans, atom (editor), git on Windows 10 x64. Is any of these the cause of the error?
My project folder is under C:\\Users\%USERNAME%\repos\algoritmi2016.
splint and git are installed both with and without cygwin. mingw64 is installed normally on Windows' cmd. gcc and make are installed under cygwin. Most of the time I am just using cygwin which points correctly to the cygwin version of splint, git, gcc and make.
I'm not using the atom shell commands, just the GUI editor.
I used Netbeans and atom only inside the ./laboratorio/lab5/es3 folder of my project. In that folder I have the Netbeans project files .project and nbproject.
On cygwin I have a symbolic link in my cygwin's home folder called repos pointing to my normal Window's %USERNAME%\repos folder. I use this link to navigate with cd quickly to my repos folder.
I tried to remove src\200student/ (is it even a folder?), using git git rm -rf ./*student --cached: it didn't match any file, unfortunately.
Is there something wrong in my setup causing this problem?
These files get added to your commit when you issue the command git add -A. If you don't want them, just don't use the -A option to git add. Instead, I recommend only adding the files that you actually want to add to your git repository, one by one.
I don't know where they are actually coming from, however. My guess is that your IDE creates these files for metadata and / or backup while you have the files open. You probably don't have to worry about them, just don't add them into your repository. Next time you want to add somefile.cpp (and maybe it's header, too), just issue the command to add only that file:
git add somefile.cpp
git add somefile.h

Issues with git branch checkout due to untracked working tree files

I thought I put the days of Xcode + git issues behind me. Guess not. I am getting this git error when trying to checkout another branch.
error: The following untracked working tree files would be overwritten by checkout:
RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme
RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist
Please move or remove them before you can switch branches.
Aborting
Very well I say, let me remove these files:
andrewjl$ git rm --cached RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
fatal: pathspec 'RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate' did not match any files
At this point I'm not sure what to do. These files are all listed in my .gitignore and I also gave git clean -f -d a try as well. No dice. Anyone know what's going on here?
The files are untracked: git rm --cached cannot find them because there are not in the index. Just delete them, using your file manager or rm. Then checkout should work as expected. Note that git status will show you what git sees the files as (tracked, changed, untracked; with an additional option it will also display ignored files).
they arent in git but there locally .. that means when you switch those would be lost and git doesnt allow that
remove them locally:
rm RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist
they are recreated by xcode anyway. nothing important in there!
Try this
git rm --cache */xcschemes/xcschememanagement.plist
git commit -m "Good bye xcschememanagement.plist"
Git stash and git checkout "yourBranch"
git clean -f
solve the problem for me, they are untracked files when run clean they get remove.

Setting up a git repository in Xcode for a pre-existing project [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Using Git with an existing Xcode project
Setting up a git repository in Xcode after a project was created. (i.e. you did not create a git repository when creating the project)
Last answer works OK, but is rather lengthy and incompatible with newer Xcode versions. I will try to reiterate it better:
Choose your git repository folder (directory) usually this will be
the directory containing the Xcode workspace or project.
In that directory, create a text file named ".gitignore", and put the following contents into it:
UserInterfaceState.xcuserstate
build
*.pbxuser
*.perspectivev3
*.mode1v3
*~
*~.nib
*~.xib
.DS_Store
xcuserdata/
Quit Xcode (If it was open)
In Terminal do the following:
\> cd <path of the repository folder>
\> git init
\> git add .
\> git commit -m "Initial commit - or whatever text you'd prefer"
You're done! Open the workspace/project in Xcode and examine your repository in the organizer window.
Quit Xcode (not sure if this is necessary but I do it just in case)
Run Terminal
Get into the project folder directory
find .
Find the file that says "UserInterfaceState.xcuserstate" and copy the entire filename up to the ./
echo "paste the UserInterfaceState.xcuserstate file here" >.gitignore
cat .gitignore
git init
git add .
git commit -m "You can type a comment here like now under source control"
You now have a repository and your project is under source control

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