Issues with git branch checkout due to untracked working tree files - xcode

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.

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

Git giving warning: unable to rmdir

I am using git bash on windows 10 which was recently updated to creators update.
whenever i am trying to switch between branches i get following thing
$ git fetch && git checkout master
warning: unable to rmdir Ionic_Developemnt: Directory not empty
Checking out files: 100% (6312/6312), done.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
I don't know why this is happening also there is a .git hidden folder in the Ionic_Development folder
Can anyone help with this why so error _/_
warning: unable to rmdir on git checkout means that you're switching to a branch where this directory doesn't exist; git tries to remove it but there are some temporary files that git cannot remove; the directory is not empty so git cannot remove it also, hence the warning.
This happens mostly when your files are still in use. I personally experienced this sometimes with atom editor. Try to close your editor, and maybe any running compilers that are watching for changes too, and try to checkout again.
Found the answer, instead of git checkout, use git checkout --recurse-submodules.
Use git config submodule.recurse true to tell git always use --recurse-submodules (only in git versions 2.14+), add --local if you want that only in local project level.
Reason:
This issue happens on (Git < 2.13) when git checkout could not take care of those submodules correctly.
Reference: https://github.com/gitextensions/gitextensions/issues/2966#issuecomment-622666568
Original Answer
Actually I think this answer is partially right :O
If a folder is tracked by local .git within that folder, it would be changed according to .git when you switch branches (e.g. deleted from our point of view, if the other branch does not have this folder).
If a folder is ignored by .gitignore, the folder would be left unchanged when you switch branches.
However, if the folder is a submodule, which is tracked by submodule .git, local .git would try use rmdir when switching branches, which caused the problem.
I know this is old, but in case anyone stumbles on this, as I did, it can also be that you're switching to a different branch and you have a Git submodule. Look for the .git hidden folder in the directory, you can delete it if you don't need it to be a submodule--just be sure to commit the folder to the parent repo in the current branch before switching.
rm -r .git

Accidentally deleted xcode project files via Git commands

I accidentally deleted all my files by committing a new build, then deleting that commit. (git commit -m, git reset -hard HEAD^). Then I tried to use (git merge ) to undo the delete. I noticed that all the missing files were back, but all the contents were missing. To clarify, all the files that were missing after I deleted the commit was back, but contents of those files only included default Xcode markups and all my coding was still missing. Is anyone familiar with an issue like this? Any guidance would be greatly appreciated..
Steps:
git commit -m
git reset -hard HEAD^
git merge
You should be able to use git fsck to see any dangling blobs or commits which remain after a reset.
git fsck --cache --no-reflogs --lost-found --unreachable HEAD
You'll see something like this with any dangling objects:
Then just do git show with the blob id to inspect
git show fd2274ea24e214457fa865e6aa74a0a1b036291a
If it's the file you want, you can then write it to a file using git show {blob id} > filename. e.g.
git show fd2274ea24e214457fa865e6aa74a0a1b036291a > test.txt

Xcode, remove files from a branch so they don't have to be merged?

I've accidentally commited my cocoapods project from my workspace into a branch.
Now that I need to merge the branch back to the master branch, I can't proceed.
I've been through all all of the files and accepted the changes in each files (which took quite a long time), however the merge aborted, with a message saying it couldn't overwrite local files.
I'd like to remove cocoapods and not have changes under git. However, I'm not sure how to proceed. I've seen that you can remove find at the command line, but I'm concerned as I'm in a branch.
Help!
What you need is probably the filter-branch feature of Git to remove some files from every commits: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#The-Nuclear-Option:-filter-branch
Try something like below on your branch:
git filter-branch --tree-filter 'rm -rf <yourCocoapods>' HEAD
In the end I physically deleted my pods folder, then committed the deleted files. I was then able to merge :)

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